rotating coordinate plane for data and text in Java

One approach is shown in SineTest. In outline,

  1. Save the graphics context’s transform.

    Graphics2D g2d = (Graphics2D) g;
    AffineTransform at = g2d.getTransform();
    
  2. Translate the origin to the center.

    g2d.translate(w / 2, h / 2);
    
  3. Invert the y-axis.

    g2d.scale(1, -1);
    
  4. Render using cartesian coordinates.

  5. Restore the transform for conventional rendering.

    g2d.setTransform(at);
    

enter image description here

Leave a Comment