作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,我从以下函数中得到“不是数字”的返回值:
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;
}
我知道 ACos 需要一个介于 -1 和 1 之间的参数值,但我不知道该怎么做,如果说末端执行器点位于 (15,15) 且长度都等于 2...
我需要规范化一切吗?包括关节之间的距离,以及从(0,0)->(15,15)的方向 vector
如有任何帮助,我们将不胜感激!
最佳答案
回想一下 right angled triangle :
cos(angle) = Adjacent/Hypotenuse
这意味着在您的 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):
Adjacent = x - l1
Hypotenuse = sqrt((x-l1)*(x-l1) + (y-l1)*(y-l1))
还要确保您正在尝试计算直角三角形而不是任意三角形的角度。
关于c++ - 逆运动学 ACos 误差 QNAN、INAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7930874/
嘿,我从以下函数中得到“不是数字”的返回值: void Spider::setAngles(double x,double y, double l1, double l2){ double theta
我是一名优秀的程序员,十分优秀!