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