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

From: Alex Hunsley (alex.hunsley_at_blueyonder.munge.co.uk)
Date: 12/21/03

  • Next message: Nick Tew: "using layers in conjunction with posting forms."
    Date: Sat, 20 Dec 2003 23:04:30 +0000
    
    

    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.

    And it does!

    > Nothing draws at all.

    This is what I'd expect...

    > 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?

    The reason you don't see anything is: by scaling all y coordinates by
    -1, you're causing all positive coords to be plotted at negative
    locations (and vice versa).. and the windows' visible space shows Y
    coords from 0 up to 800. So you end up plotting stuff off the top of
    your window, where you can't see it!

    It sounds like you're wanting to mirror the Y coordinates about the
    central horizontal line of the window.
    So y=800 maps to y=0, and y=0 maps to y=800, with the same idea applying
    to everything inbetween.

    The equation to this mirroring is: y' = 800 - y.

    IF you want to do this transformation in the Graphics2D object, as you
    appear to want to do, you do it by first scaling the Y coords by -1
    (like you're doing now), and then by adding 800 to all the Y coords (in
    other words, a 'translation' of (0, 800)).
    This will get you the result you want.
    Look at Graphics2D's translate(dx,dy) command for more help with how to
    call translation...

    alex


  • Next message: Nick Tew: "using layers in conjunction with posting forms."

    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 ... coords from 0 up to 800. ... central horizontal line of the window. ... other words, a 'translation' of ). ...
      (comp.lang.java.gui)
    • Re: Office 2007: wot a pile of shite
      ... the red dot and half not. ... I'm not confused as to why you find me confusing. ... With Windows, X means close this window, and quit if it's the last ... I think someone else here worked out that 50% of OSX apps ...
      (uk.comp.sys.mac)
    • Re: Office 2007: wot a pile of shite
      ... Like that crap with half of the apps closing with ... the red dot and half not. ... With Windows, X means close this window, and quit if it's the last ...
      (uk.comp.sys.mac)
    • Re: Red Dot in Taskbar: "Your Activity is Recorded"
      ... I have a red dot in my taskbar which says "Your activity is recorded" when ... a window appears asking for my ... I think my son downloaded some type of keylogger program and ... parental control software, particularly from a product called PC-Pandora ...
      (microsoft.public.windowsxp.help_and_support)
    • Re: Bitwise operating...is that the term?
      ... > Oh -- the reason it needs the X and Y coords of the mouse is because it ... > needs to find the window handle of the window under the mouse to send ... Prev by Date: ...
      (microsoft.public.vb.general.discussion)