360degree rotation in Java2D  
Author Message
Will Clark





PostPosted: 2003-8-29 3:35:00 Top

java-programmer, 360degree rotation in Java2D I have a bit of a problem rotating Shapes using the Graphics2D function
rotate(theta).

My high-school trig lessons indeed tell me that sine and cosine functions go
between -90 degrees and +90 degrees (or 0 and 180, if you like), and I can
see why this means that when I call the rotate(...) function, it will not
rotate the object all the way round the whole 360 degrees.

Currently, I have a duplicate Shape object which is flipped so that for one
half of the rotation the original shape is drawn, and for the second half,
the other...

There must be a better way!

Any ideas?

Cheers :o)

Will




 
Will Clark





PostPosted: 2003-8-29 4:47:00 Top

java-programmer >> 360degree rotation in Java2D Yep, sorted now!

Cheers again, it was in the use of the Math.atan function... grrr, silly
mistakes!

"Will Clark" <email***@***.com> wrote in message
news:bilp7l$5sn$email***@***.com...
> Yeah, I was using radians, but the problem remains...
>
> What's even more annoying is that I just wrote a ten line example program
to
> show you the problem I'm having, and it isn't a problem in my test applet!
>
> So I must have made a mistake somewhere else in my code, and its only
> becoming visible through the rotation. I'll suss it out somehow!
>
> Back to the drawing board (no pun intended too much!)
>
> Cheers for your thoughts though :o)
>
> "Eric Sosman" <email***@***.com> wrote in message
> news:email***@***.com...
> > Will Clark wrote:
> > >
> > > I have a bit of a problem rotating Shapes using the Graphics2D
function
> > > rotate(theta).
> > >
> > > My high-school trig lessons indeed tell me that sine and cosine
> functions go
> > > between -90 degrees and +90 degrees (or 0 and 180, if you like), and I
> can
> > > see why this means that when I call the rotate(...) function, it will
> not
> > > rotate the object all the way round the whole 360 degrees.
> >
> > Say what? Sine and cosine are defined for all numbers, not
> > just for a half-circle's worth. Yes, they're periodic, but the
> > period is the full circle.
> >
> > Just a guess at possible sources of your trouble (I'm not
> > entirely sure what your trouble *is*):
> >
> > - The argument to awt.Graphics2D.rotate(double) is
> > an angle expressed in radians, not in degrees. Use
> > Math.toRadians(double) and Math.toDegrees(double) to
> > convert back and forth if needed.
> >
> > - If you rotate a shape by 2*pi radians (360 degrees),
> > you may have some difficulty determining whether
> > anything actually happened ...
> >
> > If neither of these helps clear up your problem, post your
> > code for study.
> >
> > --
> > email***@***.com
>
>


 
Knute Johnson





PostPosted: 2003-9-4 12:30:00 Top

java-programmer >> 360degree rotation in Java2D Will Clark wrote:
> Yep, sorted now!
>
> Cheers again, it was in the use of the Math.atan function... grrr, silly
> mistakes!
>
> "Will Clark" <email***@***.com> wrote in message
> news:bilp7l$5sn$email***@***.com...
>
>>Yeah, I was using radians, but the problem remains...
>>
>>What's even more annoying is that I just wrote a ten line example program
>
> to
>
>>show you the problem I'm having, and it isn't a problem in my test applet!
>>
>>So I must have made a mistake somewhere else in my code, and its only
>>becoming visible through the rotation. I'll suss it out somehow!
>>
>>Back to the drawing board (no pun intended too much!)
>>
>>Cheers for your thoughts though :o)
>>
>>"Eric Sosman" <email***@***.com> wrote in message
>>news:email***@***.com...
>>
>>>Will Clark wrote:
>>>
>>>>I have a bit of a problem rotating Shapes using the Graphics2D
>
> function
>
>>>>rotate(theta).
>>>>
>>>>My high-school trig lessons indeed tell me that sine and cosine
>>
>>functions go
>>
>>>>between -90 degrees and +90 degrees (or 0 and 180, if you like), and I
>>
>>can
>>
>>>>see why this means that when I call the rotate(...) function, it will
>>
>>not
>>
>>>>rotate the object all the way round the whole 360 degrees.
>>>
>>> Say what? Sine and cosine are defined for all numbers, not
>>>just for a half-circle's worth. Yes, they're periodic, but the
>>>period is the full circle.
>>>
>>> Just a guess at possible sources of your trouble (I'm not
>>>entirely sure what your trouble *is*):
>>>
>>> - The argument to awt.Graphics2D.rotate(double) is
>>>an angle expressed in radians, not in degrees. Use
>>>Math.toRadians(double) and Math.toDegrees(double) to
>>>convert back and forth if needed.
>>>
>>> - If you rotate a shape by 2*pi radians (360 degrees),
>>>you may have some difficulty determining whether
>>>anything actually happened ...
>>>
>>> If neither of these helps clear up your problem, post your
>>>code for study.
>>>
>>>--
>>>email***@***.com
>>
>>
>
>

Remember that Math.atan returns theta in -pi/2 to pi/2 and that
Math.atan2 returns theta in -pi to pi.

--

Knute Johnson
email s/nospam/knute/
Molon labe...