Obtain a Degree from Position - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Obtain a Degree from Position

Im building a Graphic 2D library now(I want to upload it but I dont now where). Do you know how to get degree from position?


The angle are?


  • XLoomXLoom Posts: 129Member

    The way to get the angle from position is very simple.

    // the first position
    float x1,y1;
    // the target position
    float x2,y2;
    // vector from positions
    float vx,vy;
    // the angle in radians
    float angle;


    // This will give you right angle in radians.
    // Normally you would have to check whether the vx is not 0, but
    // double atan2(double y,float x) function
    // (dont forget to #include )
    // can manage it and it will also give you proper -PI to PI value
    // unlike atan

    // if you want to convert the radians into degrees you can do this
    #define PI 3.14159265358979323846

    float degrees;


    // or degrees into radians

    I hope this helps. (And I also hope here are no accidental mistakes, because I have been doing really ugly math in university for all day, and my brain is somewhat exhausted :)


Sign In or Register to comment.