Re: Graphics2D rotation



James McGill wrote:
I make a buffered image for the base layer, which is a circle.
Then I make another buffered image for the top layer, which is also a
circle, the same size.

I want to animate the second image on top of the first, I guess I'd call
it a "pinwheel" effect. So each timer tick, the top layer should be
redrawn in its next step of rotation.
This worked for my purpose:

...
// first translate
g2.translate(radius, radius);
// then rotate
g2.rotate(stepRadians);
// then translate back
g2.translate(-radius, -radius);
g2.drawImage(topLayerImage, 0, 0, this);
...


So I think I have to translate the origin back after rotating becuase
the image itself is oriented to that space, correct?

Ok, now I see the problem. You are drawing an image and that does not have the
center at the "origin" but at the upper left corner. I thought you were drawing
a Shape which typically has the center at the origin. Therefore, you need the
second translation. I would assume that your code should actually solve the
problem, doesn't it?

One suggestion: Once you are sure about which transformations you need,
aggregate all of them into a single AffineTransform and apply it once when
rendering the image. There are also variants of the drawImage methods that
accept an AffineTransform. Depending on how quickly your wheel rotates and how
much memory you can affort, it might be even better to generate rotated copies
of the image in a preprocessing phase so you don't have to perform the time
consuming rotation for each frame.

Cheers,
Simon
.



Relevant Pages

  • Re: translation and rotation in Euclidean space
    ... In the second place a single rotation only requires a 2x2 matrix. ... do and wish to rotate and translate a scene it is helpful if you process ... a 2d rank tensor, say Lij, a vector is a 1st rank tensor say Xi and ...
    (sci.physics.relativity)
  • Re: translation and rotation in Euclidean space
    ... In the second place a single rotation only requires a 2x2 matrix. ... do and wish to rotate and translate a scene it is helpful if you process ... a 2d rank tensor, say Lij, a vector is a 1st rank tensor say Xi and ...
    (sci.physics.relativity)
  • Re: Object rotation
    ... > need to translate back to the origin first, then rotate, then translate to ... For example rotations are ALWAYS around an axis so if you ... then moves on the new x axis after the Z rotation. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Object rotation
    ... need to translate back to the origin first, then rotate, then translate to ... For example rotations are ALWAYS around an axis so if you ... then moves on the new x axis after the Z rotation. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Calculating new coordinates in 3D after moving an object
    ... Let's say I want to rotate the line P2-P3 about 14 degrees around the axis P1-P2. ... I assume I first must find the a central point around which the rotation should be done, but since all points are moving... ... The usual method would be to translate the figure so that the ...
    (sci.math)

Loading