C++ 逆运动学ACos误差QNAN,INAN

C++ 逆运动学ACos误差QNAN,INAN,c++,animation,vector,inverse,kinematics,C++,Animation,Vector,Inverse,Kinematics,嘿,我从以下函数中得到一个返回值“不是一个数字”: void Spider::setAngles(double x,double y, double l1, double l2){ double theta1, theta2; theta2=acos((pow(x,2)+pow(y,2)-pow(l1,2)-pow(l2,2))/(2*l1*l2)); cout<<theta2* 180/PI<<endl; theta1=(-((l2*sin(theta2)*x)+(l1

嘿,我从以下函数中得到一个返回值“不是一个数字”:

void Spider::setAngles(double x,double y, double l1, double l2){
double theta1, theta2;
theta2=acos((pow(x,2)+pow(y,2)-pow(l1,2)-pow(l2,2))/(2*l1*l2));
cout<<theta2* 180/PI<<endl;
theta1=(-((l2*sin(theta2)*x)+(l1+l2*cos(theta2)*y))/((l2*sin(theta2)*y)+    (l1+l2*cos(theta2)*x)))* 180/PI;
cout<<theta1;
}
void Spider::设置角度(双x、双y、双l1、双l2){
双θ1,θ2;
θ2=acos((pow(x,2)+pow(y,2)-pow(l1,2)-pow(l2,2))/(2*l1*l2));
回想一下,对于a:

这意味着在
theta2的代码中,您有:

Adjacent = x*x + y*y - l1*l1 - l2*l2
Hypotenuse = 2*l1*l2
充其量这是向后的,更可能是错误的,这取决于您正试图做什么。如果您正试图确定斜边从(0,0)到(x+l1,y+l2)的直角三角形的角度,您将使用:

Adjacent = x + l1
Hypotenuse = sqrt((x+l1)*(x+l1) + (y+l2)*(y+l2))
或对于三角形(0,0)到(x-l1,y-l2):


另外,请确保您正在尝试计算直角三角形中的角度,而不是任意三角形。

我正在尝试用圆弧余弦求逆……也许我没有抓住您的要点!是的:颠倒我的第一个方程得到
angle=acos(Adj/Hyp)
。如果您为Adj或Hyp提供了不正确的数字,您可能会得到超出
acos()有效输入范围的结果。
Adjacent = x + l1
Hypotenuse = sqrt((x+l1)*(x+l1) + (y+l2)*(y+l2))
Adjacent = x - l1
Hypotenuse = sqrt((x-l1)*(x-l1) + (y-l1)*(y-l1))