Getting the Normal Vector Edit
(For steering and other calculations.)
Notice: This is perhaps obsolete Edit
This was written before the ability to set maneuver nodes existed in KOS. Now that maneuver nodes exist it is probably a lot easier to just use the normal and antinormal directions provided by the maneuver node system instead of doing what is described here.
However, the page is still here because there might be situations where getting the normal as a vector is useful, and getting the normal of your target rather than of yourself can be useful. So there will still be cases where the maneuver node system doesn't give you what you need.
This was written with KOS 0.71.
There are some maneuvers for which aiming perpendicularly to your current orbit plane, in the directions called "normal" and "antinormal" would be useful.
This short example shows a way to obtain the normal and anti-normal aiming vector, provided you have the short tfDirtoUnitV example program from Tutorial with example - Conversion from Directions to XYZs on this wiki.
The normal vector to your orbit can be obtained by taking a vector cross product of a vector in the upward direction (pointing out from the orbital body) and a vector in your prograde direction (the orbital velocity vector for example.).
In principle the normal vector should be in the same direction regardless of where during your orbit you sample the UP and VELOCITY:ORBIT vectors.
This example calculates "norm" - a unit vector in the normal direction, and "antiNorm" - a unit vector in the antiNormal direction. It also shows you how that could be used for steering.
It also calculates "inc" - your inclination angle relative to the SOI body, since that's easy once you have your normal vector (it's just the angle of how far off the normal vector is from the SOI body's northerly axis direction.)
This assumes you've already installed tfDirToUnitV.txt view from Tutorial with example - Conversion from Directions to XYZs on this wiki.
If you have not done this, it will not run.
run tfDirToUnitV( Up ). set uVec to tfUnit. set vVec to velocity:orbit. // The math is less wildly swingy when using // numbers closer to zero, so converting // orbital velocity into a unit vector here. // (Alternatively, you could run // tfDirToUnitV( prograde ). // to obtain the velocity unit vector in the // global variable tfUnit .) // set vMag to ( ((vVec:x)^2)+((vVec:y)^2)+((vVec:z)^2) )^0.5 . set vUnitX to (vVec:x) / vMag. set vUnitY to (vVec:y) / vMag. set vUnitZ to (vVec:z) / vMag. // Cross Product of up and velocity // gives a vector normal to the orbital // plane. Don't bother collecting the XYZ // parts into a vector as I need to keep // using them seperately anyway: set normX to (vUnitY)*(uVec:z) - (vUnitZ)*(uVec:y) . set normY to (vUnitZ)*(uVec:x) - (vUnitX)*(uVec:z) . set normZ to (vUnitX)*(uVec:y) - (vUnitY)*(uVec:x) . // Now the vectors: set norm to V(normX,normY,normZ). set antiNorm to V( 0-normX, 0-normY, 0-normZ ). // Inclination can be obtained from the dot product // of the normal vector and the SOI body's axis: // Since we're dealing with unit vectors here, and // the direction of the SOI body's axis is always // the Y axis, as in V(0,1,0), most of the terms // of that dot product cancel out and we're left // with just this simple calculation: set inc to arccos( normY ). print " ". print " norm is " + norm. print "antiNorm is " + antiNorm. print "My inclination from body's equator is: " + inc . print " ". print "Now try typing either of the following: ". print " lock steering to R(0,0,0) + norm. ". print " lock steering to R(0,0,0) + antiNorm. ". print "To set your steering.". print " ".