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

From: Raymond DeCampo (rdecampo_at_spam-I-am-not.twcny.rr.com)
Date: 12/20/03


Date: Sat, 20 Dec 2003 05:40:09 GMT

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



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 ... able to do this by shifting up m pixels, ... // first shift "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 ... > 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.developer)
  • 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: Help needed on hot pixels
    ... pixels that might be of some interest: I have a Panasonic FX7 pocket ... will still have a red dot there. ... A partial solution to your problem might also be found with ...
    (rec.photo.digital)