360degree rotation in Java2D

Discussion in 'Java' started by Will Clark, Aug 28, 2003.

  1. Will Clark

    Will Clark Guest

    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 :eek:)

    Will
     
    Will Clark, Aug 28, 2003
    #1
    1. Advertising

  2. Will Clark

    Will Clark Guest

    Yep, sorted now!

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

    "Will Clark" <> wrote in message
    news:bilp7l$5sn$...
    > 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 :eek:)
    >
    > "Eric Sosman" <> wrote in message
    > news:...
    > > 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.
    > >
    > > --
    > >

    >
    >
     
    Will Clark, Aug 28, 2003
    #2
    1. Advertising

  3. Will Clark

    Roedy Green Guest

    On Thu, 28 Aug 2003 20:47:25 +0000 (UTC), "Will Clark"
    <> 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.
     
    Roedy Green, Aug 28, 2003
    #3
  4. Will Clark wrote:
    > Yep, sorted now!
    >
    > Cheers again, it was in the use of the Math.atan function... grrr, silly
    > mistakes!
    >
    > "Will Clark" <> wrote in message
    > news:bilp7l$5sn$...
    >
    >>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 :eek:)
    >>
    >>"Eric Sosman" <> wrote in message
    >>news:...
    >>
    >>>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.
    >>>
    >>>--
    >>>

    >>
    >>

    >
    >


    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...
     
    Knute Johnson, Sep 4, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marco Schmidt

    Re: Using Component based on Java2D

    Marco Schmidt, Jul 1, 2003, in forum: Java
    Replies:
    0
    Views:
    815
    Marco Schmidt
    Jul 1, 2003
  2. Bura Tino

    Java2D transparency: a long delay

    Bura Tino, Jul 1, 2003, in forum: Java
    Replies:
    4
    Views:
    1,212
    S. Balk
    Jul 2, 2003
  3. markus brosch

    [java2D] colored gradient

    markus brosch, Aug 18, 2003, in forum: Java
    Replies:
    7
    Views:
    902
    markus brosch
    Aug 19, 2003
  4. Karl Mueller
    Replies:
    1
    Views:
    1,946
    Karl Mueller
    Jan 8, 2004
  5. muckyduck
    Replies:
    0
    Views:
    332
    muckyduck
    Jan 26, 2004
Loading...

Share This Page