A little geometry help for offset rotation

tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
edited April 2012 in Working with GS (Mac)
I have a line that rotates in a circle on a fixed point (lineX, lineY). I want another line to be offset by about 10 pixels so that it is always on a tangential line to the circle that the initial line is creating when it rotates. A picture is worth a thousand words so:

image

Knowing the x,y values for the fixed point (the blue dot) and the rotation angle for the first line, how can I determine the x,y values for the second line (the red dot)?

The closest I've gotten is x=10*sin(lineAngle)+lineX; y=10*cos(lineAngle)+lineY. Unfortunately, it works okay but then the red line crosses over the blue line instead of staying on the tangent/circle.

Best Answer

Answers

  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    edited April 2012
    Try x=cos(blulineangle)*10+linex y=sin(bluelineangle)+liney

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @MarkOnTheIron It just does the same thing and overlaps.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Ah, okay, so I just had my cos and sin mixed up. You're right... thanks for the demo!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2012
    Sorry, one more question: this works if my actors are verticle to begin with (e.g. width=4, height=80), but not when they start out horizontal (e.g. height=4, width=80). How would I adjust the math to work with horizontal actors?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @MarkOnTheIron So this is what happens when I make the actors horizontal: http://dl.dropbox.com/u/19602014/LineRotationHorizontal.zip
  • jckmcgrawjckmcgraw Member Posts: 647
    @tatiang
    Ah, okay, so I just had my cos and sin mixed up. You're right... thanks for the demo!
    Soh - Cah - Toa !! (Indian chanting or whatever :P)

    Sine is opp/hyp
    Cos is adj/hyp
    Tan is opp/adj

    That just helped me on my CST today :)

    Jack McGraw
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2012
    Well, I did remember SohCahToa, I just somehow had the trig functions in the wrong relation to x and y. My initial sketch was this:

    image
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2012
    LOL... actually, that worked. I just plugged in my equations with horizontal lines and it worked. I just had to broadcast game.Angle = self.rotation+180 because the angle that my center point line was reporting was a negative number.
  • jckmcgrawjckmcgraw Member Posts: 647
    @tatiang

    Well... I didn't do much but glad it's working!

    Jack McGraw
  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    Without having too much complicated functions instead of changing the height and width of the actor to make them horizontal, just change the actor rotation to 90 that way my demo will still work.

    Also if you don't want too many constraints you can unlock the red actor and access the blue actor positions and rotation directly without having to constrain them to a game attribute.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @MarkOnTheIron I needed to have the rotation of my actors at 0, but you're right that does work.

    And thanks for the suggestion about constraints. I try to use unlocked scene attributes whenever possible.
Sign In or Register to comment.