REM Axis Translation ..... Rev 3.2 REM A J Tooth / 30th Dec 2002 REM Illustrates Rotation of Axes using EULER ANGLES. REM Also utilises TRUE Perspective. REM Call Utility Procedures PROC_fullscreen : REM Set up use of Full Screen REM Set up Initial Axis Arrays REM Dimension Axes Array and Projection Array DIM axorig(6,3) : DIM axnow(6,3) : DIM alpbet(6,2) : DIM pos(6,2) DIM Mat(3,3) REM Loads Initial Axes Vertex Vectors RESTORE FOR a%=0 TO 6 FOR b%=1 TO 3 READ axorig(a%,b%) NEXT b% NEXT a% REM Place Origin and Draw Axes PRINT " STATUS: Input Parameters " INPUT " Vertical Height ",vht GOTO 310 300 PRINT " Horizontal Distance must not be less than 1! " 310 INPUT " Horizontal Distance ",hdis IF hdis<=1 THEN GOTO 300 COLOUR 7 INPUT " Initial Rotation ",thetamax% INPUT " Axial Tilt ",phimax% REM Centres Graphics and sets scale R=SQR(vht*vht+hdis*hdis) xmax%=1024 : zmax%=768 scl%=INT(750*R) ORIGIN xmax%,zmax% : GCOL 3 sp$=GET$ REM Rotation Section REPEAT PRINT TAB(0,0);" STATUS: Initial Axial Rotation "; FOR theta%=0 TO thetamax% PROC_mainsub(theta%,0,0) NEXT theta% PRINT TAB(0,0);" STATUS: Axial Tilt "; FOR phi%=0 TO phimax% PROC_mainsub(thetamax%,phi%,0) NEXT phi% FOR psi%= 0 TO 180 STEP 2 PRINT TAB(0,0);" STATUS: Angle ";psi%;" degrees "; PROC_mainsub(thetamax%,phimax%,psi%) NEXT psi% PROC_mainsub(0,0,0) PRINT TAB(0,0);" STATUS: ALL ROTATIONS COMPLETED "; sp$=GET$ UNTIL (sp$="s" OR sp$="r") IF sp$="r" THEN RUN QUIT END REM End of Programme --------------------------------------- REM Initial Axis Vectors DATA 0,0,0 DATA 1,0,0,0,1,0,0,0,1 DATA -1,0,0,0,-1,0,0,0,-1 REM--------------------------------------------------------- REM Master Subroutine DEF PROC_mainsub(theta%,phi%,psi%) PROC_rotmat(theta%,phi%,psi%) PROC_axrot(axorig(),Mat()) FOR c%=1 TO 6 PROC_alpha(vht,hdis,c%) PROC_beta(vht,hdis,c%) NEXT c% IF psi%=180 OR ((theta%=0 OR theta%=thetamax%) AND phi%=0 AND psi%=0) THEN cont%=0 ELSE cont%=1 ENDIF PROC_axdraw(cont%) ENDPROC REM--------------------------------------------------------- REM Rotation Matrix Update DEF PROC_rotmat(Theta%,Phi%,Psi%) LOCAL Th,Ph,Ps Th=RAD(Theta%) : Ph=RAD(Phi%) : Ps=RAD(Psi%) Mat(1,1)= COS(Ps)*COS(Ph)*COS(Th) -SIN(Ps)*SIN(Th) Mat(1,2)=-SIN(Ps)*COS(Ph)*COS(Th) -COS(Ps)*SIN(Th) Mat(1,3)=-SIN(Ph)*COS(Th) Mat(2,1)= COS(Ps)*COS(Ph)*SIN(Th) +SIN(Ps)*COS(Th) Mat(2,2)=-SIN(Ps)*COS(Ph)*SIN(Th) +COS(Ps)*COS(Th) Mat(2,3)=-SIN(Ph)*SIN(Th) Mat(3,1)= COS(Ps)*SIN(Ph) Mat(3,2)=-SIN(Ps)*SIN(Ph) Mat(3,3)= COS(Ph) ENDPROC REM--------------------------------------------------------- REM Update Position Vectors with Each Rotation DEF PROC_axrot(axorig(),Mat()) LOCAL i%,j%,k%,cum FOR i%=1 TO 6 FOR j%=1 TO 3 cum=0 FOR k%=1 TO 3 cum=cum + Mat(j%,k%)*axorig(i%,k%) NEXT k% axnow(i%,j%)=cum NEXT j% NEXT i% ENDPROC REM--------------------------------------------------- REM Draw Axes on Screen DEF PROC_axdraw(Control%) LOCAL k%,a$ FOR k%=1 TO 6 MOVE 0,0 r%=k% MOD 3 GCOL r%+1 PLOT 5,scl%*pos(k%,1),scl%*pos(k%,2) SYS "UpdateWindow",@hwnd% IF Control%=0 THEN GOTO 1450 a$=INKEY$(1) IF theta%=thetamax% AND phi%=phimax% THEN GCOL 4 ELSE GCOL 8 MOVE 0,0 PLOT 13,scl%*pos(k%,1),scl%*pos(k%,2) 1450 REM Goto HERE to Avoid Undrawing NEXT k% ENDPROC REM-------------------------------------------------- REM Calculates line of sight distance for 2-D View Angle DEF FN_rdis(Vht,Hdis,Vr%) LOCAL xd,yd,zd xd=axnow(Vr%,1) : yd=axnow(Vr%,2)+Hdis : zd=axnow(Vr%,3)-Vht =SQR(xd*xd+yd*yd+zd*zd) REM Calculates normalising factor for normal to position vector plane DEF FN_npl(Vht,Hdis,Vr%) LOCAL xd,yd,zd xd=Hdis*axnow(Vr%,1) : yd=Vht*axnow(Vr%,1) : zd=Vht*axnow(Vr%,2)+Hdis*axnow(Vr%,3) =SQR(xd*xd+yd*yd+zd*zd) REM-------------------------------------------------- REM Angle between vertical plane and plane containing position vector DEF PROC_alpha(Vht,Hdis,Ver%) LOCAL npl,num npl=FN_npl(Vht,Hdis,Ver%) num=Vht*axnow(Ver%,2)+Hdis*axnow(Ver%,3) IF npl=0 THEN alpbet(Ver%,1)=PI/2 ELSE alpbet(Ver%,1)=ACS(num/npl) IF axnow(Ver%,1)>0 THEN alpbet(Ver%,1)=2*PI-alpbet(Ver%,1) ENDPROC REM 2-D Projection View-Angle DEF PROC_beta(Vht,Hdis,Ver%) LOCAL rdis rdis=FN_rdis(Vht,Hdis,Ver%) yfact=Hdis*(Hdis+axnow(Ver%,2)) : zfact=Vht*(Vht-axnow(Ver%,3)) alpbet(Ver%,2)=ACS((yfact+zfact)/(rdis*R)) REM Convert from Polar to x/y Coords for Printing to Screen pos(Ver%,1)=alpbet(Ver%,2)*(-SIN(alpbet(Ver%,1))) pos(Ver%,2)=alpbet(Ver%,2)*COS(alpbet(Ver%,1)) ENDPROC REM-------------------------------------------------- REM Set up use of Full Screen DEF PROC_fullscreen SYS "GetSystemMetrics", 0 TO xscreen% SYS "GetSystemMetrics", 1 TO yscreen% SYS "SetWindowLong",@hwnd%,-16,&16000000 SYS "SetWindowPos",@hwnd%,-1,0,0,xscreen%,yscreen%,0 vdu 23,22,xscreen%;yscreen%;8,16,16,1 : rem Set fullscreen mode MOUSE OFF : OFF : REM Turns off the Mouse Pointer and the Cursor ENDPROC REM--------------------------------------------------