Re: Flipping Y axis in a Graphics 2D??

From: Josh D.King (jking_at_coloradocollege.edu)
Date: 12/20/03

  • Next message: Alex Hunsley: "Re: Flipping Y axis in a Graphics 2D??"
    Date: 20 Dec 2003 12:11:00 -0800
    
    

    Raymond DeCampo <rdecampo@spam-I-am-not.twcny.rr.com> wrote in message news:<ZgREb.34502$UY6.29129@twister.nyroc.rr.com>...
    > Chris Grant wrote:
    > > Hello:
    > >
    > > I am trying to do something that is supposed to be simple (?). In the
    > > attached code, I have drawn a red dot at top right and blue dot at
    > > lower left. I am tryin to flip the Y axis so I expect the red dot at
    > > the lower right and the blue at the top left using:
    > >
    > > Graphics2D g2d = (Graphics2D)getGraphics();
    > > g2d.scale(1, -1);
    > >
    > > The -1 is supposed to flip the y axis. Nothing draws at all. If you
    > > comment out the g2d.scale(1, -1); line, then everything works fine.
    > > What am I doing wrong. Can you please show how I would correct it to
    > > do what I want?
    > >
    >
    > Well, since the top left corner is (0,0), flipping the y-axis causes all
    > of your rendering to be done above the component where it will not be
    > seen. What you really want to do is flip about the line y = m, where m
    > is the y-coordinate of the midpoint of the component. You should be
    > able to do this by shifting up m pixels, then flipping and then shifting
    > down m pixels:
    >
    > // Untested, uncompiled code
    > int m = getHeight()/2;
    > // last-specified-first-applied (see java.awt.Graphics2D#transform)
    > // last shift "down" (positive) m pixels
    > g2d.translate(0,m);
    > // flip about y-axis
    > g2d.scale(1,-1);
    > // first shift "up" (negative) m pixels
    > g2d.translate(0,-m);
    >
    > HTH,
    > Ray

    A simple flip and translate will work as well
      g2d.scale(1,-1);
      g2d.translate(0,getHeight());

    rather than shifting everything halfway, flipping, and then shifting
    everything again


  • Next message: Alex Hunsley: "Re: Flipping Y axis in a Graphics 2D??"

    Relevant Pages

    • Re: Flipping Y axis in a Graphics 2D??
      ... I am tryin to flip the Y axis so I expect the red dot at ... > Well, since the top left corner is, flipping the y-axis causes all ... > able to do this by shifting up m pixels, ...
      (comp.lang.java.gui)
    • Re: Flipping Y axis in a Graphics 2D??
      ... I am tryin to flip the Y axis so I expect the red dot at ... able to do this by shifting up m pixels, ... // first shift "up" m pixels ...
      (comp.lang.java.developer)
    • Re: Flipping Y axis in a Graphics 2D??
      ... I am tryin to flip the Y axis so I expect the red dot at ... able to do this by shifting up m pixels, ... // first shift "up" m pixels ...
      (comp.lang.java.gui)