valkan
July 31, 2022, 1:54pm
1
Hey folks. I am trying to find bearing between two points. For that I need to use sin, and cos. However I can not make any good results from these. For example I try something like this:
float X,Y;
void setup() {
Serial.begin (9600);
X=cos(38.627);
Y=sin(4.381);
Serial.print("X:= ");
Serial.println(X);
Serial.print("Y:= ");
Serial.println(Y);
}
What I am getting from it is X=0.60, and Y=-0.95. The actual calculation of cos(38.627) is 0,781225, and sin(4.381)=0,17364. What am I doing wrong?
1 Like
valkan:
What am I doing wrong?
Forgetting to convert from radians to degrees. Multiply the result by (180.0/PI).
1 Like
Don't multiply the result. Multiply the argument.
Indeed, for some reason I was thinking of the inverse functions. For trig function arguments in degrees, convert to radians by multiplying as follows
X=cos(38.627*PI/180.0);
Y=sin(4.381*PI/180.0);
system
Closed
February 1, 2023, 12:40am
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.