Given a unit-length vector to be used as the Z axis of a coordinate system, the arbitrary axis algorithm generates a corresponding X axis for the coordinate system. The Y axis follows by application of the right-hand rule.
The method is to examine the given Z axis (also called the normal vector). If it is close to the positive or negative world Z axis, cross the world Y axis with the given Z axis to arrive at the arbitrary X axis. If it is not close, cross the world Z axis with the given Z axis to arrive at the arbitrary X axis. The boundary at which the decision is made was chosen to be both inexpensive to calculate and completely portable across machines. This is achieved by having a sort of “square” polar cap, the bounds of which are 1/64, which is precisely specifiable in six decimal-fraction digits and in six binary-fraction bits.
Let the given normal vector be called N.
Let the world Y axis be called Wy, which is always (0,1,0).
Let the world Z axis be called Wz, which is always (0,0,1).
If (abs (Nx) < 1/64) and (abs (Ny) < 1/64) then
Ax = Wy X N (where “X” is the cross-product operator).
Ax = Wz X N.
Scale Ax to unit length.
Ay = N X Ax. Scale Ay to unit length.