C# Trig Point To Point Angle (Yaw) Question

Discussion in 'General Programming Support' started by rover2341, May 10, 2014.

  1. rover2341

    rover2341 Is riding a roller coaster...Wee!

    Ratings:
    +114 / 0 / -0
    Edit**

    SOLVED


    I have a XY Point (Start) And a XY Point (End)

    I am trying to get the YAW Between them or the angle between them.
    [​IMG]

    I want the THICK RED Angle. So that would be around 290 or so.

    I have been using this. But It doesent always work.
    REF: http://stackoverflow.com/questions/...-angle-between-a-line-and-the-horizontal-axis

    Code:
     float x = XPosition - tracks.Last().Position.X;
    float y = YPosition - tracks.Last().Position.Y;
    
    
    yawGoal = Math.Abs(Convert.ToSingle(Math.Atan2((double)x, (double)y) * 180 / Math.PI));

    //These Work But

    F-B FAILS (Comes up with 115, That is a good angle, But in my project it gos Stright Right...)
    G-B FAILS (Comes up with 115, That is a good angle, But in my project it gos Stright Right...)

    Points.png

    Any thoughts?

    Edit*

    Looks like Mine Game is setup....

    not 0-90-180-270
    but 90-180-270-0

    Hmm.. But something is wack maybe my axis is reverse too..

    Edit**

    SOLVED

    Code:
                    if (XPosition < tracks.Last().Position.X)
                        yawGoal = yawGoal + 90;
    this fixed it.
     
    Last edited: May 10, 2014

Share This Page