为什么cos()只需在我的计算器上需要rad

问题描述 投票:-1回答:2

请给我的Arduino狗使用此代码但它不起作用,因为我没有cos()操作的弧度转换成弧度,但最终我需要获得角度(cos()操作后)。

const int b = 200; //Lengt
const int Pin = A0; //Pot pin
int c = 0; //Variable for Angle
int d = 0; //
int e = 0; //Final side size

void setup() {
  Serial.begin(9600);
}

void loop() {
c = analogRead(Pin);//Read potval write to variable c
c = map(c, 0, 1023, 0, 180);//Map potval to Angle
c = cos(c)//Calculate Cosinus
d = b - (b * c);//200 - (200 * c)
e = sqrt(d)//Calcute √e
Serial.print(e)//Print out final side a
}


//Example:
//d = 200 − (200 * 0,6560)
//d = 200 − 131,2 = 68.8
//e = √68.8
//e = 8.29

math arduino trigonometry robot
2个回答
0
投票

您的问题是“为什么?”

答案是:因为它是在C ++中定义的。


0
投票

因为函数cos()被定义为以弧度为参数:https://www.arduino.cc/reference/en/language/functions/trigonometry/cos/

弧度是角度的SI unit,大多数编程库都希望角度参数以弧度为单位。大多数科学计算器都有一个按钮,可以在弧度和度数(有时甚至是梯度)之间进行切换。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.