DXF Group Codes
Advanced DXF Issues |
Object Coordinate Systems (OCS)
|
Arbitrary Axis Algorithm
|
The arbitrary axis algorithm is used by AutoCAD internally to implement the arbitrary but consistent generation of object coordinate systems for all entities which use object coordinates.
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) and see if it is close to the positive or negative World Z axis. If it is, cross the World Y axis with the given Z axis to arrive at the arbitrary X axis. If not, 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 is 1/64, which is precisely specifiable in six decimal-fraction digits and in six binary-fraction bits.
The algorithm does the following. (All vectors are assumed to be in 3D space and specified in the World Coordinate System).
Let the given normal vector be called N.Let the world Z axis be called Wz, which is always (0,0,1).
Here we are looking for the arbitrary X and Y axes to go with the normal N. They will be called Ax and Ay. N could also be called Az (the arbitrary Z axis) as follows:
If (abs (Nx) < 1/64) and (abs (Ny) < 1/64) thenScale Ax to unit length.
The method of getting the Ay vector is
Ay = N X Ax. Scale Ay to unit length.