【问题标题】:Given two rotational angles, how do I calculate an orbital position?给定两个旋转角,我如何计算轨道位置?
【发布时间】:2012-06-04 23:56:25
【问题描述】:

我通过调整两个旋转角度 - 围绕被跟踪对象的 X 轴和 Y 轴旋转,在 3D 空间中围绕另一个对象移动卫星。给定这些角度和半径,如何计算对象的最终位置?

这仅适用于 y 轴旋转:

position.x = otherObject.position.x + Math.cos(yRotation) * radius;
position.y = otherObject.position.y;
position.z = otherObject.position.z + Math.sin(yRotation) * radius;

但一旦我尝试合并 x 轴旋转,事情就会变得很奇怪。

【问题讨论】:

    标签: math language-agnostic 3d


    【解决方案1】:

    您可以使用这些方程式在 2D 中旋转某些东西(请参阅 Wikipedia):

    x' = x * cos(angle) - y * sin(angle)
    y' = x * sin(angle) + y * cos(angle)
    

    您可以使用基本相同的方程在 3D 中绕 x/y/z 轴旋转,例如绕 y 轴旋转:

    x' = x * cos(angle) - z * sin(angle)
    y' = y
    z' = x * sin(angle) + z * cos(angle)
    

    我想你想做的是:

    • 围绕 y 轴旋转 yRotation
    • 然后通过 xRotation 绕 x 轴旋转

    您已经完成了 y 轴旋转。所以从 (x, y, z) = (radius, 0, 0) 开始,你已经完成了:

    x' = x * cos(angley) - z * sin(angley) = radius * cos(angley)
    y' = y = 0
    z' = x * sin(angley) + z * cos(angley) = radius * sin(angley)
    

    我们只需要再次应用方程来绕 x 轴旋转:

    x'' = x' = radius * cos(angley)
    y'' = y' * cos(anglex) - z' * sin(anglex) = -radius * sin(angley) * sin(anglex)
    z'' = y' * sin(anglex) + z' * cos(anglex) = radius * sin(angley) * cos(anglex)
    

    请注意,调整“y 轴”旋转不一定会使卫星绕 y 轴旋转(例如,如果您的 x 旋转为 90 度,那么调整 y 旋转实际上会绕 z 轴旋转)。如果您不喜欢这种行为,我建议您只存储卫星 (x, y, z)(相对于跟踪对象)并直接调整它(您可能希望在每次调整后重新归一化以确保浮动点不准确不会使您的卫星漂移)。

    【讨论】:

    • 如果我认为你说的计算应该是:position.x = otherObject.position.x + Math.cos(yRotation) * radius; position.y = otherObject.position.y - Math.sin(yRotation) * Math.sin(xRotation); position.z = otherObject.position.z + Math.sin(yRotation) * Math.cos(xRotation) * 半径; ?如果是这样,那也行不通。如果这有助于理解问题,我可以在某处发布完整代码。
    • 更正:position.x = otherObject.position.x + Math.cos(yRotation) * 半径; position.y = otherObject.position.y - Math.sin(yRotation) * Math.sin(xRotation) * 半径; position.z = otherObject.position.z + Math.sin(yRotation) * Math.cos(xRotation) * 半径;还是不行……
    • @korona 是的,我就是这么说的。我很难理解为什么“不起作用” - 我相信它与您发布的解决方案基本相同,但有一些细微差别:您的以 (x, y, z) = (0, 0 , 半径) 而不是 (radius, 0, 0);你的先旋转 x (你正在做 outv = RY * RX * inv);您的 x 旋转方向相反。
    【解决方案2】:

    我的解决方案最终是使用根据旋转角度计算的变换矩阵,如下所示:

    var mtx = new THREE.Matrix4();
    mtx.rotateY(yRotation);
    mtx.rotateX(xRotation);
    var v = new THREE.Vector3(mtx.elements[8], mtx.elements[9], mtx.elements[10]);
    v.multiplyScalar(radius);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多