Re: Flipping Y axis in a Graphics 2D??
From: Raymond DeCampo (rdecampo_at_spam-I-am-not.twcny.rr.com)
Date: 12/20/03
- Next message: Chris Smith: "Re: Target VM Microsoft? or Java Lint to check for MS VM compatibility?"
- Previous message: Raymond DeCampo: "Re: waiting message"
- In reply to: Chris Grant: "Flipping Y axis in a Graphics 2D??"
- Next in thread: Josh D.King: "Re: Flipping Y axis in a Graphics 2D??"
- Reply: Josh D.King: "Re: Flipping Y axis in a Graphics 2D??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Chris Smith: "Re: Target VM Microsoft? or Java Lint to check for MS VM compatibility?"
- Previous message: Raymond DeCampo: "Re: waiting message"
- In reply to: Chris Grant: "Flipping Y axis in a Graphics 2D??"
- Next in thread: Josh D.King: "Re: Flipping Y axis in a Graphics 2D??"
- Reply: Josh D.King: "Re: Flipping Y axis in a Graphics 2D??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|