Arduino - 三角函式



您需要在實踐中使用三角函式,例如計算運動物體的距離或角速度。Arduino 提供了傳統的三角函式 (sin、cos、tan、asin、acos、atan),可以透過編寫其原型來總結。Math.h 包含三角函式的原型。

三角函式精確語法

double sin(double x); //returns sine of x radians
double cos(double y); //returns cosine of y radians
double tan(double x); //returns the tangent of x radians
double acos(double x); //returns A, the angle corresponding to cos (A) = x
double asin(double x); //returns A, the angle corresponding to sin (A) = x
double atan(double x); //returns A, the angle corresponding to tan (A) = x

示例

double sine = sin(2); // approximately 0.90929737091
double cosine = cos(2); // approximately -0.41614685058
double tangent = tan(2); // approximately -2.18503975868
廣告