* see comments at end-of-file program define _3dproj version 2.1 set output error capture drop _vx _vy _vybase /* set unspecified angles to default values */ if "%_1"=="" { mac def _1 "%D3rot" } if "%_2"=="" { mac def _2 "%D3elev" } if "%_3"=="" { mac def _3 "%D3tilt" } noisily conf number %_1 noisily conf number %_2 noisily conf number %_3 /* Store the angles actually used in the D3l.. sequence */ mac def D3lrot "%_1" mac def D3lelev "%_2" mac def D3ltilt "%_3" di in gr " note: projecting at rot(" in ye "%_1" in gr ") elev(" /* */ in ye "%_2" in gr ")" /* convert the angles into radians, store as _SC(1..3) */ gen _SC=(360-%_1)*_pi/180 in 1 replace _SC=(270-%_2)*_pi/180 in 2 replace _SC=%_3*_pi/180 in 3 /* generate sin and cos of each angle */ replace _SC=sin(_SC[1]) in 4 replace _SC=cos(_SC[1]) in 5 replace _SC=sin(_SC[2]) in 6 replace _SC=cos(_SC[2]) in 7 replace _SC=sin(_SC[3]) in 8 replace _SC=cos(_SC[3]) in 9 /* roate about z-axis (rotation) */ gen _newy=_x*_SC[4]+_y*_SC[5] /* rotate about x-axis (elevation) and y-axis (tilt) */ gen _vybase = _newy*_SC[7] gen _vy=_vybase - _z*_SC[6] gen _vx=(_x*_SC[5]-_y*_SC[4])*_SC[9]+(_newy*_SC[6]+_z*_SC[7])*_SC[8] format _vybase _vy _vx %2.0f drop _newy _SC end exit /* _3dproj [rotate# [elev# [tilt#]]] projects the variables _x, _y, and _z into the variables _vy and _vx using the designated or default rotation angles. Also produces _vybase which is the projection of (_x, _y, 0). _vybase is only valid under the assumption that tilt==0. _vy, _vx, _vybase may already exist, but if so, are dropped and recreated. Caller should make arrangements to capture the break key. Data is left in unusable condition if break. Notes: The three angles are really z-rotation, x-rotation, and y-rotation. The coordinate system (internally) is y | | +----- x / / z (right-hand) We favor the following: z y | / | / +----- x However, the rotation transformations (with small angles) produce z x | / | / +----- y If so, this should be disguised from the using by invterchanging the arguments to _3dproj */