acos ist definiert in der math
, die in C über math.h
, bzw. in C++ über cmath
eingebunden wird.
acos() berechnet den Arcus Cosinus des übergebenen Parameters. Der Arcus Cosinus ist die Umkehrfunktion des Cosinus.
#include <math.h> double acos ( double x ); float acos ( float x ); // nur C++ long double acos ( long double x ); // nur C++ float acosf( float x ); long double acosl( long double x );
x: Wert, dessen Winkel bestimmt werden soll, gültig zwischen -1 und +1.
Return value: Winkel im Bereich von 0 bis π(Kreiszahl Pi)
Eine beliebte Fehlerquelle ist zu übersehen, dass der Computer Winkel im Bogenmaß berechnet, also von 0 bis π (Kreiszahl Pi). Winkel von 0 bis 180 Grad müssen umgerechnet werden
#include <stdlib.h> // für EXIT_SUCCESS #include <math.h> // für acos #include <stdio.h> // für printf() #define PI 3.141592654 int main( void ) { double value, degree; double length = 0.5; value = acos( length ); degree = value * 180 / PI; printf( "acos(%f) sind %f bzw. %f Grad\n", length, value, degree ); return EXIT_SUCCESS; }
Ausgabe:
acos(0.500000) sind 1.047198 bzw. 60.000000 Grad
In C++ wird diese Funktion mit einem ValueArray-Template überladen.