I have a 2d velocity vector that is on the orbital plane, which is fine if my orbits are 2d and not retrograde. But I need to turn that into a 3d vector relative to the parent body/barycenter, and take inclination into account.
I think this is what HopDavid was referring to at the end of the post when he mentions a matrix rotation, and what HavesterR is doing with the quaternion, but I don't quite understand what he's doing there. Can anyone enlighten me?
To convert the 2d vector to a 3d vector (relative to the coordinate system of a parent body), one needs 'rotate' to the x-y-z reference frame of the parent body from the natural, perifocal reference frame of the elliptical/hyperbolic orbit. This rotation is defined in terms of three angles: the longitude of the ascending node ([MATH]\Omega[/MATH]); the orbital inclination ([MATH]\iota[/MATH]); and the argument of periapsis ([MATH]\omega[/MATH]). These are just the three standard orbital elements that define the orientation of the orbit in space. They are also the Euler angles that define a rotation from one reference frame (the perifocal) to another.
The perifocal reference frame is defined by three unit vectors (which we can call [MATH]\hat{p}[/MATH], [MATH]\hat{q}[/MATH] and [MATH]\hat{w}[/MATH]) each at right angles to each other - in exactly the same way as the three unit vectors [MATH]\hat{x}[/MATH], [MATH]\hat{y}[/MATH] and [MATH]\hat{z}[/MATH] are right angles to each other in the reference frame of the parent body. Here, though, the [MATH]\hat{p}[/MATH] unit vector points from the origin (i.e. the position of the gravitating body) towards the orbital periapsis; the [MATH]\hat{q}[/MATH] unit vector points at right-angles to that vector but in the direction of the orbital motion and also lying in the orbital plane; and the[MATH]\hat{w}[/MATH] unit vector is perpendicular to the orbital plane (and to the other two vectors). For example, if one knows the orbital radius ([MATH]r[/MATH]) and true anomaly ([MATH]\nu[/MATH]) of a satellite, the perifocal coordinates of the satellite is just [MATH](r\,\cos(\nu),\,r\,\sin(\nu),\,0)[/MATH]). This is why the perifocal reference frame is useful: it leads to simple expressions for the position and velocity vectors of a satellite.
In terms of the x-y-z coordinate system, the x-y-z components of the perifocal unit vectors, [MATH]\hat{p}[/MATH], [MATH]\hat{q}[/MATH] and [MATH]\hat{w}[/MATH], can be written as:
[MATH]
\begin{aligned}
p_{x}&=\cos(\omega)\,\cos(\Omega)-\cos(\iota)\,\sin(\omega)\,\sin(\Omega)\\p_{y}&=\cos(\iota)\,\sin(\omega)\,\cos(\Omega)+\cos(\omega)\,\sin(\Omega)\\p_{z}&=\sin(\iota)\,\sin(\omega)
\end{aligned}
[/MATH]
[MATH]
\begin{aligned}
q_{x}&=-\sin(\omega)\,\cos(\Omega)-\cos(\iota)\,\cos(\omega)\,\sin(\Omega)\\q_{y}&=\cos(\iota)\,\cos(\omega)\,\cos(\Omega)-\sin(\omega)\,\sin(\Omega)\\q_{z}&=\sin(\iota)\,\cos(\omega)
\end{aligned}
[/MATH]
[MATH]
\begin{aligned}
w_{x}&=\sin(\iota)\,\sin(\Omega)\\w_{y}&=-\sin(\iota)\,\cos(\Omega)\\w_{z}&=\cos(\iota)
\end{aligned}
[/MATH]
From this, it's easy to calculate the position (or velocity) vector of the satellite in the 3d x-y-z coordinates of the body-centric coordinate system. Taking the position example above, the x-y-z coordinates are given by:
[MATH]r\,\cos(\nu)\,(p_x, p_y, p_z) + r\,\sin(\nu)\,(q_x, q_y, q_z) + 0\,(w_x, w_y, w_z)[/MATH]
The net effect of these transformations is to perform a rotation of the perifocal reference frame using the three Euler angles, [MATH]\Omega[/MATH], [MATH]\iota[/MATH] and [MATH]\omega[/MATH].
As an example, let's suppose that in the perifocal reference frame, the vector you wish to transform is [MATH](1.0, 2.0, 0.0)[/MATH]. Let's also suppose that the orbital longitude of the ascending node is 180 degrees; the orbital inclination is 25 degrees; and the argument of periapsis is 10 degrees. We calculate the x-y-z coordinates of the unit vectors as:
[MATH]\hat{p} = (-0.984808,-0.157379,0.0733869)[/MATH]
[MATH]\hat{q} = (0.173648,-0.892539,0.416198)[/MATH]
[MATH]\hat{w} = (0,0.422618,0.906308)[/MATH]
so that the x-y-z coordinates of the perifocal vector [MATH](1.0, 2.0, 0.0)[/MATH] is:
[MATH]1.0\times(-0.984808,-0.157379,0.0733869) + 2.0\times(0.173648,-0.892539,0.416198) + 0.0\times (0,0.422618,0.906308)[/MATH]
or just:
[MATH](-0.637511,-1.94246,0.905782)[/MATH]
Does that help?