英文:
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<double, 3> plane = Eigen::Hyperplane<double, 3>::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() << point1.z() << point2.z() << 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论