在计算法向量和z坐标旋转时的数值错误。

huangapple go评论64阅读模式
英文:

Wrong Values in the calculation of normalVector and z-coordinate rotation

问题

auto it = vectorList.begin();
Eigen::Vector3d point1 = *it++;
Eigen::Vector3d point2 = *it++;
Eigen::Vector3d point3 = *it;

我正在使用它们创建一个平面,并获取其法向量。

Eigen::Hyperplane<double, 3> plane = Eigen::Hyperplane<double, 3>::Through(point1, point2, point3);
Eigen::Vector3d normalVector = plane.normal();
normalVector = normalVector.normalized();

我正在计算法向量与z轴之间的角度,并将其用作x轴的旋转矩阵。现在我想确保所有值都具有相同的z值。

double anglezaxis;
anglezaxis = std::atan2(normalVector.x(), normalVector.z());
Eigen::AngleAxisd rotation(anglezaxis, Eigen::Vector3d::UnitX());
point1 = rotation * point1;
point2 = rotation * point2;
point3 = rotation * point3;
qDebug() << point1.z() << point2.z() << point3.z();

但是z值完全不同。我的思维错误在哪里?

英文:

I have three points-> point1, point2..

auto it = vectorList.begin();
Eigen::Vector3d point1 = *it++;
Eigen::Vector3d point2 = *it++;
Eigen::Vector3d point3 = *it;

I am using them for creating a plane, and taking the normal vector of it.

Eigen::Hyperplane&lt;double, 3&gt; plane = Eigen::Hyperplane&lt;double, 3&gt;::Through(point1, point2, point3);
Eigen::Vector3d normalVector = plane.normal();
normalVector = normalVector.normalized();

I am calculating the angle between the normalvector and the z-axis and using it as a rotationmatrix (for the x-axis). Now I want to get sure all values have the same z-value.

double anglezaxis;
anglezaxis = std::atan2(normalVector.x(), normalVector.z());
Eigen::AngleAxisd rotation(anglezaxis, Eigen::Vector3d::UnitX());
point1 = rotation*point1;
point2 = rotation *point2;
point3 = rotation * point3;
qDebug() &lt;&lt; point1.z() &lt;&lt; point2.z() &lt;&lt; point3.z();

but the z values are completly different. Where is my thinking mistake?

答案1

得分: 1

如果您希望飞机处于z=常数的位置,那么您需要将法向量旋转回z轴上。用于旋转的轴是法向量和unitZ的垂直轴,例如通过叉乘,而不是x轴。角度的符号也与您当前的相反,并且最好通过单位法向量的z方向余弦来计算。

英文:

If you want the plane to be z=constant then you need to rotate the normal vector back onto the z axis. The rotation axis for that is perpendicular to normal vector and unitZ - e.g. by cross product - not the x axis. The angle also has the opposite sign to what you currently have and is better worked out from the z direction cosine of the unit normal vector.

huangapple
  • 本文由 发表于 2023年7月11日 05:18:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76657405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定