C acos
In C, acos returns the inverse cosine in radians. For real inputs from −1 to 1, the result lies between 0 and π.
A simple example
acos
- Start with 1
- Do this Find the angle with cosine 1
- Result 0 radians
#include <stdio.h>
#include <math.h>
int main(void) {
printf("%.15g\n", (double) (acos(1.0)));
}
0
Syntax
acos(reachFraction)
Run these examples in C
Save one example at a time as lesson.c. Use C17 and a Unix-style shell.
cc -std=c17 -Wall -Wextra lesson.c -lm -o lesson
./lessonRecover the angle of an awning arm
A designer is positioning an awning over a window. Relate the length of its arm to the horizontal distance it covers so a drawing can show the reach at a chosen angle.
#include <math.h>
#include <stdio.h>
int main(void) {
double reachFraction = 0.5;
printf("%.3f\n", acos(reachFraction));
return 0;
}
1.047
A reach of half the arm length corresponds to about 1.047 radians, or 60 degrees.
Read a solar panel diagram
A model solar panel is 2 m long. Its horizontal projection is 1.6 m, and a student wants the tilt angle for a drawing.
Divide the horizontal projection by the sloping length before taking inverse cosine.
Check a closed display lid
A desktop display lid lies flat in a model. Its projected width equals its full width, so a designer checks the angle reported by the model.
A cosine ratio of one corresponds to zero tilt.
What to watch for
Clamp small measurement-rounding errors to the valid interval only if your application justifies doing so.