1

I'm moving around a satellite around another object in 3D space by adjusting two rotational angles - rotation about the X and Y axes of the tracked object. How do I calculate the objects final position given those angles and a radius?

This works fine for just the y-axis rotation:

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

But as soon as I try and incorporate the x-axis rotation, things get weird.

4

2 に答える 2

2

これらの方程式を使用して、2Dで何かを回転させることができます(ウィキペディアを参照)。

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で回転
  • 次に、x軸を中心にxRotationで回転します

すでに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)を(追跡対象に対して)保存し、それを直接調整することをお勧めします(調整のたびに再正規化して、浮動小数点を確保することをお勧めしますポイントが不正確であっても、衛星がドリフトすることはありません)。

于 2012-06-05T02:40:07.830 に答える