در مواردی مانند محاسبه فاصله اشیاء متحرک یا سرعت زاویه ای نیازمند توابع مثلثاتی هستیم. آردوینو مجموعه ای از توابع مثلثاتی پایه (sin, cos, tan, asin, acos, atan) را در قالب کتابخانه Math.h در اختیار ما قرار می دهد.
ساختار توابع مثلثاتی :
1 2 3 4 5 6 | 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 |
مثال :
1 2 3 | double sine = sin(2); // approximately 0.90929737091 double cosine = cos(2); // approximately -0.41614685058 double tangent = tan(2); // approximately -2.18503975868 |