Velocity Reviews > Java > 360degree rotation in Java2D

# 360degree rotation in Java2D

Will Clark
Guest
Posts: n/a

 08-28-2003
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 )

Will

Will Clark
Guest
Posts: n/a

 08-28-2003
Yep, sorted now!

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

"Will Clark" <(E-Mail Removed)> wrote in message
news:bilp7l\$5sn\$(E-Mail Removed)...
> 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 )
>
> "Eric Sosman" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.
> >
> > --
> > http://www.velocityreviews.com/forums/(E-Mail Removed)

>
>

Roedy Green
Guest
Posts: n/a

 08-28-2003
On Thu, 28 Aug 2003 20:47:25 +0000 (UTC), "Will Clark"
<(E-Mail Removed)> wrote or quoted :

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

Mathematically arctan has many possible solutions. Any atan
implementation has to pick a range for its canonical solutions to fall
in.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Knute Johnson
Guest
Posts: n/a

 09-04-2003
Will Clark wrote:
> Yep, sorted now!
>
> Cheers again, it was in the use of the Math.atan function... grrr, silly
> mistakes!
>
> "Will Clark" <(E-Mail Removed)> wrote in message
> news:bilp7l\$5sn\$(E-Mail Removed)...
>
>>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 )
>>
>>"Eric Sosman" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>
>>>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.
>>>
>>>--
>>>(E-Mail Removed)

>>
>>

>
>

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

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Louise Digital Photography 19 02-02-2004 08:37 AM Michele Puccini Java 0 09-19-2003 12:49 PM markus brosch Java 7 08-19-2003 10:05 AM Bura Tino Java 4 07-02-2003 01:58 PM Marco Schmidt Java 0 07-01-2003 09:55 AM

Advertisments