首页 > 解决方案 > 向量双重计算以在 C++ 中找到角度

问题描述

我有以下代码

constexpr double pi = 3.14159265358979323846;
cout << "RAV dot product is " << normalization1.first.DotProduct(normalization2.first) << endl;
cout << "acos of 1 is " << std::acos(1) * (180/pi) << endl;
double dotproductvalue = normalization1.first.DotProduct(normalization2.first);
cout << "dot product value: " << std::fixed << dotproductvalue << endl;
cout << "RAV angel is " << std::acos(dotproductvalue) * (180 / pi) << endl;
return std::acos(normalization1.first.DotProduct(normalization2.first)) * (180 / pi); // return in 

度数

当我在产品上方运行时,我观察到以下输出

问题 3:

Intersection of lines 1.182000x_1+ 5.562000x_2 = 6.744000
  and 1.773000x_1+ 8.343000x_2 = 9.525000
 are
RAV dot product is 1.000000
acos of 1 is 0.000000
dot product value: 1.000000
RAV angel is -nan(ind)

我无法在上面的代码中找到什么是错误 为什么 angel 显示为 -nan(ind) 而不是零?

请帮助调试。

谢谢

标签: c++double

解决方案


推荐阅读