title: How can I draw on JPanel using another quadrant for the coordinates?
body: <p>I would like to draw some shapes on a JPanel by overriding <code>paintComponent</code>. I would like to be able to pan and zoom. Panning and zooming is easy to do with <code>AffineTransform</code> and the <code>setTransform</code> method on the <code>Graphics2D</code> object. After doing that I can easyli draw the shapes with <code>g2.draw(myShape)</code> The shapes are defined with the "world coordinates" so it works fine when panning and I have to translate them to the canvas/JPanel coordinates before drawing.</p>
  
  <p>Now I would like to change the <a href="http://en.wikipedia.org/wiki/Cartesian_coordinate_system#Two-dimensional_coordinate_system" rel="nofollow noreferrer">quadrant</a> of the coordinates. From the 4th quadrant that JPanel and computer often uses to the 1st quadrant that the users are most familiar with. The X is the same but the Y-axe should increase upwards instead of downwards. It is easy to redefine origo by <code>new Point(origo.x, -origo.y);</code></p>
  
  <p><b>But How can I draw the shapes in this quadrant?</b> I would like to keep the coordinates of the shapes (defined in the world coordinates) rather than have them in the canvas coordinates. So I need to transform them in some way, or transform the <code>Graphics2D</code> object, and I would like to do it <b>efficiently</b>. Can I do this with <code>AffineTransform</code> too?</p>
  
  <p>My code for drawing:</p>
  
  <pre><code>        public void paintComponent(Graphics g) {
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(Color.blue);
  
              AffineTransform at = g2.getTransform();
              at.translate(-origo.x, -origo.y);
              at.translate(0, getHeight());
              at.scale(1, -1);
              g2.setTransform(at);
              g2.drawLine(30, 30, 140, 20);
              g2.draw(new CubicCurve2D.Double(30, 65, 23, 45, 23, 34, 67, 58));
          }
  </code></pre>