I am trying to write a program to calculate the resulting bearing of the addition of two vectors. Magnitude is not required.
The bearing is defined as the bearing of the tip of the second vector from the tail of the first vector.
The program crashes when I tried to run it. Also I'm aware that the functions are not returning expected results.
Any help appreciated. Thanks in advance.
#include <iostream>
#include <math.h>
#define PI 3.14159265358979323846264338
using namespace std;
int _atan(int y, int x)
{
if (x=0)
{
return 90*abs(y)/y;
}
else
{
return atan(y/x)*180/PI;
}
}
int _bearing(int x0, int y0, int x1, int y1)
{
int bearing;
bearing=90-_atan(y1-y0, x1-x0);
if (bearing<0)
{
bearing=bearing+360;
}
return bearing;
}
int _vectorAdd(int m1, int b1, int m2, int b2)
{
_bearing(0, 0, m1*sin(b1)+m2*sin(b2), m1*cos(b1)+m2*cos(b2));
}
int main()
{
int m1;
int b1;
int m2;
int b2;
scanf("%d %d %d %d", &m1, &b1, &m2, &b2);
printf("%d\n", _vectorAdd(m1, b1, m2, b2));
}