Thread: Angle of rotation formula depending on sprite position

  1. #16
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Wait, I think you misunderstood.
    Both sine and cosine are non-negative when 0 <= θ <= 90, right?
    You saw that when you rotated the "grey square" around the origin by 90 degrees that its X coordinate was from the negative side, right?
    Code:
    sinθ >= 0
    sin(θ + 90) < 0 <==> cosθ < 0
    X = cosθ
    
    cosθ >= 0
    cos(θ + 90) < 0 <==> sinθ < 0, but the Y coordinate is positive, so -sinθ > 0
    Υ = -sinθ
    Devoted my life to programming...

  2. #17
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    lol, sorry but I get confused each post...
    em, if the angle>=0 && angle <= 90 (but why 90? Should be 180, I assuming it is nonnegative because it is a unit circle)
    another thing, how is the X coordinate from the negative side? No matter how much I rotate the "grey square" its x axis will always be positive.
    left is negative, right positive..or am I reading it wrong?
    (In my CV I write "I'm a quick learner, that's lie :P")
    Last edited by Eman; 05-31-2011 at 01:54 PM.
    You ended that sentence with a preposition...Bastard!

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Eman View Post
    lol, sorry but I get confused each post...
    em, if the angle>=0 && angle <= 90 (but why 90? Should be 180, I assuming it is nonnegative because it is a unit circle)
    another thing, how is the X coordinate from the negative side? No matter how much I rotate the "grey square" its x axis will always be positive.
    Then you need to rotate further. When you rotate 90 degrees, the tip of the arrow will be pointing straight up. If you keep turning, that tip must needs keep moving to the left, and left is negative.

    (EDIT: Or think of it as a clock: we start out pointing at three o'clock. Positive angle corresponds to moving "up", which is counter-clockwise. So after 90 degrees we are pointing at twelve o'clock, and then we start point at 11, 10, and then 9 -- and all of those are on the left side of the clock, where x is negative.)

  4. #19
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    I get that explanation tabstop thanks. So any easier explanations to apply this to know whether to use cos or sin to find x or y? :O
    Code:
    sinθ >= 0
    sin(θ + 90) < 0 <==> cosθ < 0
    X = cosθ
    
    cosθ >= 0
    cos(θ + 90) < 0 <==> sinθ < 0, but the Y coordinate is positive, so -sinθ > 0
    Υ = -sin
    I don't understand that..remember I suck at maths, I'd rather it be in English or diagrams, I know you guys are helping me and it is asking too much..but I can't learn reading symbols and stuff it makes my mind go blank
    You ended that sentence with a preposition...Bastard!

  5. #20
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Just a minute, this thread started because you couldn't feagure out how your changes actually worked. We answered that, and tried to explain it as simple as possible. What don't you understand?
    Devoted my life to programming...

  6. #21
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You seem to be calculating the angle relative to the ship's heading, then trying to interpret it as an absolute angle, which of course explains why your calculation seems to depend on the ship's heading...
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #22
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    @brewbuck...it is exactly what I am trying to do..but I can't figure out or visualize how .

    how to derive the formula like Sipher did
    Last edited by Eman; 05-31-2011 at 04:12 PM.
    You ended that sentence with a preposition...Bastard!

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    SOHCAHTOA

    sin goes with the side opposite the angle (which is always going to be y) and cos goes with the side adjacent to the angle (which will always be x), (on the assumption that we are measuring from "standard position" which is three o'clock).

  9. #24
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    yep, but what if the arrow is facing upwards at 12 0'clock at 90 degrees..
    then that formula changes...
    cos will be used to find y.
    sin will be used to find x.
    but to find y it will
    be y= -cos angle
    but why -cos but no -sin for x? million dollar question
    You ended that sentence with a preposition...Bastard!

  10. #25
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You mean if you start with the arrow facing upwards at 12 o'clock? Then:

    SOHCAHTOA

    sin goes with the side opposite the angle. If you start measuring at 12 o'clock, then the side opposite the angle is the bit at the top, so sin gives you x, and cos gives you y. x is immediately negative (since you're moving to the left). y won't be negative until you get further down past 9 o'clock into 8, 7, 6 o'clock.

  11. #26
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Angle of rotation formula depending on sprite position-unitcircle-jpg
    there..

    EDIT: Just saw your post
    since I am moving left so if the angle is between 45 and 90 it is negative? and it is between 0 and 45 it is positive?
    so if I go past 180 degrees then y becomes negative?
    oh and don't laugh at my picture please
    Last edited by Eman; 05-31-2011 at 05:00 PM.
    You ended that sentence with a preposition...Bastard!

  12. #27
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Your arrow is currently at 45 degrees. Does that look like the tip of that arrow is at 0 in either direction? No? Then I guess 45 degrees isn't 0, which means it can't possibly be the shift between positive and negative.

  13. #28
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    true, the red arrow is from the origin to when it intersects the circle..a normalized vector..and that was to show where the new x axis is...but if I was to draw it this way:
    Angle of rotation formula depending on sprite position-unitcircle-jpg

    the arrow is now at 12 (90 degrees)..but what makes it negative? it hasn't fully crossed over to the left side as in 11.59 where the normalized length is now -1..btw is that even relevant to finding the formula?
    You ended that sentence with a preposition...Bastard!

  14. #29
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Length is never never never never never never never never never negative. (Your position on an axis can be negative, but even when you are at -1, the distance from you to the zero-point is still 1. Sometimes people use "directed distance" for position, but this does not appear to be one of those times.) When you are at 90 degrees, cos(90) is 0 and sin(90) is 1, which correctly gives you the point (0,1). If you go further to say 120 degrees, cos(120) is -0.5 and sin(120) is 0.866, so when your arrow points to 11 o'clock you get the point (-0.5, 0.866) which matches.

  15. #30
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Hey, stop abusing my image!
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sprite Rotation and in Direction C# and XNA
    By Eman in forum Game Programming
    Replies: 9
    Last Post: 02-21-2011, 11:06 PM
  2. Sprite Rotation With Sdl
    By Warlax in forum Game Programming
    Replies: 4
    Last Post: 08-15-2006, 12:49 PM
  3. Sprite/Image Rotation in SDL
    By Blizzarddog in forum Game Programming
    Replies: 4
    Last Post: 03-18-2005, 11:19 AM
  4. Sprite rotation
    By kawk in forum Game Programming
    Replies: 1
    Last Post: 01-25-2005, 01:39 PM
  5. sprite rotation in allegro
    By thedumbmutt in forum Game Programming
    Replies: 4
    Last Post: 01-14-2003, 08:43 AM