;__________________________________Reference Triangle Demo_______________ ;CYBER CONTROL 1.1 REQUIRED ;RAM DISK(at least 2K) required. (Or change all "D:\" to "A:\") ;This is a simple demo of the Reference Triangle Alignment routine used in ;PT7_DEMO.CTL and FLEXDEMO.CTL. scripts. It makes use of the CADCONV.PRG ;to obtain the x,y,z coordinates of individual vertices. ;Two special Right Triangle objects -- one with a known orientation ;(I call it the "Source Triangle"), and one with an arbitrary location ;and orientation ("Destination Triangle) -- are used to re-orient ;a simple Arrow-shaped object. ;The BEARING command from Cyber Control 1.1 is used here, but we go ;even further -- providing the proper adjustments to the orientation ;around the axis determined by the BEARING command. ;The file "REFTRI.3D2 contains the objects necessary to run this demo. ;Load that file before running this demo. ;The Source Triangle must be have it's vertical and horizontal legs ;aligned with CAD's Y and Z axies respectively (as they are when you load ;the REFTRI.3D2 file or create a Triangle with the routine at the very ;bottom of this file. So you may move (i.e Drag) the Source Triangle to ;any location (together with the Arrow object), but DO NOT ROTATE IT. ;The Destination Triangle gan be moved or rotated in any manner. (Just ;stay away from the very edge of the CAD Universe so that the Arrow object ;has room when it's moved to the Destination Triangles location). ;After the script is run, the Arrow object will be moved and re-oriented ;matching the Destination triangle. ; _____________________________________Reference Triangle Alignment______ ; Referenced-Tree Sub-Routines ; group a should contain only Source Triangle ; group b should contain only Destination Triangle @RTA ;___________________________________Setup CAD groups group a:clrgrp:select RTSource group b:clrgrp:select RTDest ;=======================Read Source Triangle vertices===================== group a ;________Filnames ending in "_AC" are converted to ASCII .TXT files savegrp "D:\RT_AC.3D2" ;__________________________Open and read ASCII file fopen "D:\RT_AC.TXT":ftrap EOFILE fread objects,verts ;__________________________Store vertices in variables fread a0x,a0y,a0z,b0x,b0y,b0z,c0x,c0y,c0z fclose ;____________________Set Rotation center (Right angle vertex of Source) center A:setarb a0x,a0y,a0z ;==================Read Destination Triangle vertices===================== group b savegrp "D:\RT_AC.3D2" fopen "D:\RT_AC.TXT":ftrap EOFILE fread objects,verts fread a1x,a1y,a1z,b1x,b1y,b1z,c1x,c1y,c1z fclose ;__________________________________Make Clones of Source for later use clone RTSource,Tri1:clone Tri1,Tri2 ;==================Use BEARING to establish heading======================= bearing a1x,a1y,a1z,b1x,b1y,b1z,hab,vab hab=int(hab):vab=int(vab) ;______________________________Select ONLY Source Triangle group c:clrgrp:select RTSource ;______________________________Rotate with values from BEARING rotate vab,0,0:rotate 0,0,hab ;______________________________Translate to new position xlate a1x-a0x,a1y-a0y,a1z-a0z ;=====================ReRead Source vertices in new position============= group c:clrgrp:select RTSource savegrp "D:\RT_AC.3D2" fopen "D:\RT_AC.TXT":ftrap EOFILE fread objects,verts fread a2x,a2y,a2z,dx,dy,dz,c2x,c2y,c2z fclose ;================Determine absolute Y-Axis rotation value================= @YROT x1=c1x-a1x:y1=c1y-a1y:z1=c1z-a1z x2=c2x-a1x:y2=c2y-a1y:z2=c2z-a1z ;______The constant value (1000 in this case) mus match the length of ;the two short legs of the Right Triangle Objects. R=(x1*x2+y1*y2+z1*z2)/(1000*1000) if SQR(1-(R*R))=0 then ya=0:dir=1:RETURN ya=90-ATN(R/SQR(1-(R*R))) ;=====================Test for Y-Axis rotation direction================= ;Clones of Source Triangle are rotated clockwise and counter-clockwise ;around the Y-Axis before bearing alignment to determine proper direction. group b:clrgrp:select Tri1 rotate 0,ya*-1,0 clrgrp:select Tri2 rotate 0,ya,0 select Tri1 rotate vab,0,0:rotate 0,0,hab xlate a1x,a1y,a1z for lop=0 to 1 if lop=0 then group a:clrgrp:select Tri1 if lop=1 then group a:clrgrp:select Tri2 ;_____________________________Read vertices of clone triangles savegrp "D:\RT_AC.3D2" fopen "D:\RT_AC.TXT":ftrap EOFILE fread objects,verts fread a3x,a3y,a3z,dx,dy,dz,c3x,c3y,c3z fclose ;________Determine which is closest to Destination Triangle's orientation dx=ABS(c1x-c3x):dy=ABS(c1y-c3y):dz=ABS(c1z=c3z) if lop=0 then d1= dx+dy+dz if lop=1 then d2= dx+dy+dz next lop dir=1:if d1