朝向 3d 空间中的物体旋转
我在 3d 空间的 2d 平面上有两个坐标,并且正在尝试旋转一个坐标(向量)以面对另一个坐标。我的垂直轴是 y 轴,因此如果两个坐标都位于 2d 平面上,则它们的 y 轴都为 0,并且它们的 x 和 z 坐标决定了它们在 2d 平面上的位置长度/宽度方向飞机。现在,我正在像这样计算角度(与语言无关):
angle = atan2(z2-z1,x2-x1);
并且像这样在空间中旋转/平移:
pushMatrix();
rotateY(angle);
popMatrix();
但这似乎不起作用。我的计算/过程正确吗?
i have two coordinates on a 2d plane in 3d space, and am trying to rotate one coordinate (a vector) to face the other coordinate. my vertical axis is the y-axis, so if both of the coordinates are located flat on the 2d plane, they would both have a y-axis of 0, and their x and z coordinates determine their position length/width-wise on the plane. right now, i'm calculating the angle like so (language agnostic):
angle = atan2(z2-z1,x2-x1);
and am rotating/translating in space like so:
pushMatrix();
rotateY(angle);
popMatrix();
this doesn't seem to be working though. are my calculations/process correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白你的问题(请参阅我的评论),但如果你正在寻找两个向量之间的弧度角差,请取它们点积的反余弦。点积中的向量必须标准化。
你正在使用棕褐色,要么我不明白你想要做什么,要么使用棕褐色是错误的。
I don't really understand your question (see my comment) but if you're looking for the angle difference in radians between two vectors take the arc cos of their dot product. The vectors in the dot product have to be normalized.
You're using tan, either I don't get what you're trying to do or using tan is wrong.