【发布时间】:2017-02-24 01:42:31
【问题描述】:
我尝试使用 Rodrigues 的旋转公式(Rodrigues' rotation formula):
vector3 vector3::rotate(const vector3 &axis, double theta) const
{
double cos_theta = cos(theta);
double sin_theta = sin(theta);
vector3 rotated = *this*cos_theta + (axis^*this)*sin_theta + axis*(axis*(*this))*(1 - cos_theta);
return rotated;
}
但它似乎无法正常工作。我不知道我在这里缺少什么,任何帮助将不胜感激。
编辑:
这些是我使用的运算符:
vector3 operator*(double) const; //multiplication by scalar
friend vector3 operator*(double, const vector3&); //multiplication by scalar
double operator*(const vector3&) const; //dot product
vector3 operator^(const vector3&) const; //cross product
并且它们已经过测试(它们可以正常工作)。
【问题讨论】:
-
axis^*this您似乎重载了我们没有定义的运算符...恐怕我们无法为您提供太多帮助(除非错误出现在我们无法做到的那一行肯定的) -
@Borgleader 抱歉,我编辑了我的问题。
-
@Eutherpy 您介意发布minimal reproducible example 并告诉我们到底出了什么问题(输入、输出、预期输出)。
-
轴是否应该是单位向量?
-
可能很愚蠢的问题:
theta是度数还是弧度?此外,将来拥有专用的dot和cross函数可能会更容易,因此其他人(或未来的你)不必查看*和^可能在做什么。