Phr*_*xus 1 c++ math exception angle
在处理sin/cos/tan/acos时,有没有人看到过这种奇怪的价值?数学的东西?
=== WEIRD VALUE ===
-1.#IND00
=====================
void inverse_pos(double x, double y, double& theta_one, double& theta_two)
{
// Assume that L1 = 350 and L2 = 250
double B = sqrt(x*x + y*y);
double angle_beta = atan2(y, x);
double angle_alpha = acos((L2*L2 - B*B - L1*L1) / (-2*B*L1));
theta_one = angle_beta + angle_alpha;
theta_two = atan2((y-L1*sin(theta_one)), (x-L1*cos(theta_one)));
}
Run Code Online (Sandbox Code Playgroud)
这是我正在处理的代码.
在特定条件下 - 例如当x和y为10和10时, 此代码将-1.#IND00存储到theta_one和theta_two中.
它看起来不像字符或数字:(
毫无疑问,atan2/acos/stuff是问题所在.
但问题是,try和catch不起作用,因为那些双变量已经成功地存储了一些值.
此外,以下计算永远不会抱怨它,永远不会破坏程序!
我正在考虑强制以某种方式使用此值并使整个程序崩溃...所以我可以捕获此错误..
除了这个想法,我不知道 如何检查这些theta_one和theta_two变量是否存储了这个疯狂的值.
有什么好主意吗?
先感谢您..