math - Given two rotational angles, how do I calculate an orbital position? -


i'm moving around satellite around object in 3d space adjusting 2 rotational angles - rotation x , y axes of tracked object. how calculate objects final position given angles , radius?

this works fine 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 try , incorporate x-axis rotation, things weird.

you can rotate in 2d using these equations (see wikipedia):

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

you can use same equations rotating x/y/z axes in 3d, eg rotating y axis:

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

i think want is:

  • rotate yrotation y axis
  • then rotate xrotation x axis

you've done y axis rotation. starting (x, y, z) = (radius, 0, 0), you've done:

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

we have apply equations again rotate x axis:

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) 

note adjusting "y axis" rotation won't rotate satellite y axis (eg if x rotation 90 degrees, adjusting y rotation rotate z axis). if don't behaviour, suggest storing satellite (x, y, z) (relative tracked object) , adjusting directly (you'll want re-normalise after each adjustment ensure floating point inaccuracy doesn't make satellite drift away).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -