Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you have the end points of the line, then getting the angle is pretty straightforward:

#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
    float x0 = 0.0f;
    float y0 = 0.0f;

    float x1 = 1.0f;
    float y1 = 1.0f;

    float rise = y1 - y0;
    float run  = x1 - x0;

    float pi = 4.0f*atanf(1.0);

    float angle_radians = atanf(rise/run);
    float angle_degrees = angle_radians/pi*180.0f;

    cout << rise << endl;
    cout << run << endl;
    cout << angle_radians << endl;
    cout << angle_degrees << endl;

    return 0;
}

If you have the end points of the line, then getting the angle is pretty straightforward:

#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
    float x0 = 0.0f;
    float y0 = 0.0f;

    float x1 = 1.0f;
    float y1 = 1.0f;

    float rise = y1 - y0;
    float run  = x1 - x0;

    float pi = 4.0f*atanf(1.0);
4.0f*atanf(1.0f);

    float angle_radians = atanf(rise/run);
    float angle_degrees = angle_radians/pi*180.0f;

    cout << rise << endl;
    cout << run << endl;
    cout << angle_radians << endl;
    cout << angle_degrees << endl;

    return 0;
}

If you have the end points of the line, then getting the angle is pretty straightforward:

#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
    float x0 = 0.0f;
    float y0 = 0.0f;

    float x1 = 1.0f;
    float y1 = 1.0f;

    float rise = y1 - y0;
    float run  = x1 - x0;

    float pi = 4.0f*atanf(1.0f);

    float slope = rise/run;

    float angle_radians = atanf(rise/run);
atanf(slope);
    float angle_degrees = angle_radians/pi*180.0f;

    cout << rise << endl;
    cout << run << endl;
    cout << angle_radians << endl;
    cout << angle_degrees << endl;

    return 0;
}