home *** CD-ROM | disk | FTP | other *** search
- REM @(#)CADKEY SOLIDS torus.cdl 2.2 10/31/88
- rem program to draw torus in space
-
- array vmat[9]
- array vmat1[9]
- array vmat2[9]
-
- :radius1
- REM Positive radius for the torus
-
- getflt "Radius of the torus (%f) =>", 1.0, rad1
- if (@key <= -2)
- exit
- if (rad1 > 0.00001)
- goto radius2
- pause "Invalid radius ... (Press RETURN)"
- goto radius1
-
- :radius2
- REM Positive radius for the cross section
-
- getflt "Radius of cross section (%f) =>", 0.5, rad2
- if (@key == -3)
- exit
- if (@key == -2)
- goto radius1
- if ((rad2 < rad1) && (rad2 > 0.00001))
- goto method
- pause "Invalid radius ... (Press RETURN)"
- goto radius2
-
- :method
- REM The plane of the torus can be defined by two methods. NORMAL requires the
- REM user to indicate two points which determine the line. The plane of the
- REM torus is perpendicular to this line. This option is default.
- REM PLANE lets the user indicate a plane for the torus.
-
- getmenu "Choose method for defining torus plane",\
- "NORMAL",\
- "PLANE"
-
- if (@key == -3)
- exit
- if (@key == -2)
- goto radius2
- if (@key == 2)
- goto plane
-
- def = 3
- :first
- getpos "Indicate 1st pt. along the normal", def
- if (@key == -1)
- goto first
- if (@key == -3)
- exit
- if (@key == -2)
- goto method
-
- def = @key
- x1 = @xworld
- y1 = @yworld
- z1 = @zworld
-
- :second
- getpos "Indicate 2nd pt. along the normal", def
- if (@key == -1)
- goto second
- x2 = @xworld
- y2 = @yworld
- z2 = @zworld
-
- def = @key
- if (@key == -3)
- exit
- if (@key == -2)
- goto first
- if (@key == -1)
- goto second
-
- REM direction vector for the cone axis has to be non-zero
- xn = x2 - x1
- yn = y2 - y1
- zn = z2 - z1
-
- if ((abs(xn) > 0.00001) || \
- (abs(yn) > 0.00001) || \
- (abs(zn) > 0.00001))
- goto unit
-
- pause "2nd pt. is coincident with 1st pt. (Press RETURN)"
- goto second
-
- :unit
- REM Take cross product of (0, 1, 0) with the direction vector to get x axis.
- REM If the result is a zero vector, the dirction vector is parallel to
- REM (0, 1, 0), so take direction vector cross (1, 0, 0) to get y axis. Once
- REM the x axis or y axis is determined, find the remaining axis by taking
- REM cross of the direction vector and the axis determined, thus completing
- REM the orthogonal basis
-
- rem x axis
- call cross, xx, xy, xz, 0, 1, 0, xn, yn, zn
-
- if ((abs(xx) < 0.00001) && \
- (abs(xy) < 0.00001) && \
- (abs(xz) < 0.00001))
- goto use_x
-
- call cross, yx, yy, yz, xn, yn, zn, xx, xy, xz
- goto vmatrix
-
- :use_x
- call cross, yx, yy, yz, xn, yn, zn, 1, 0, 0
- call cross, xx, xy, xz, yx, yy, yz, xn, yn, zn
-
- :vmatrix
- REM Determine the vector magnitudes and convert the orthogonal basis to a
- REM orthnormal basis
-
- mn = sqrt(xn*xn + yn*yn + zn*zn)
- mx = sqrt(xx*xx + xy*xy + xz*xz)
- my = sqrt(yx*yx + yy*yy + yz*yz)
-
- REM Define the view matrix for the new view and two othe views perpendicular
- REM to this view (for drawing the cross section circles). Then goto defining
- REM these views
-
- vmat2[2] = -(vmat1[0] = (vmat[0] = xx/mx))
- vmat2[1] = (vmat1[2] = (vmat[1] = yx/my))
- vmat2[0] = -(vmat1[1] = -(vmat[2] = xn/mn))
- vmat2[5] = -(vmat1[3] = (vmat[3] = xy/mx))
- vmat2[4] = (vmat1[5] = (vmat[4] = yy/my))
- vmat2[3] = -(vmat1[4] = -(vmat[5] = yn/mn))
- vmat2[8] = -(vmat1[6] = (vmat[6] = xz/mx))
- vmat2[7] = (vmat1[8] = (vmat[7] = yz/my))
- vmat2[6] = -(vmat1[7] = -(vmat[8] = zn/mn))
- goto def_view
-
- :plane
- REM If the PLANE option is chosen, get the view matrix by GETPLANE command
-
- getplane "Define plane for the torus", 1
-
- if (@key == -3)
- exit
- if (@key == -2)
- goto method
-
- getmenu "Accept plane (YES) ? ",\
- "NO",\
- "YES"
-
- on (@key+3) goto exit, plane, , , plane, plmat
-
- :plmat
- REM Define the view matrix for the new view and two othe views perpendicular
- REM to this view (for drawing the cross section circles). Then goto defining
- REM these views
-
- vmat2[2] = -(vmat1[0] = (vmat[0] = @fltdat[1]))
- vmat2[1] = (vmat1[2] = (vmat[1] = @fltdat[2]))
- vmat2[0] = -(vmat1[1] = -(vmat[2] = @fltdat[3]))
- vmat2[5] = -(vmat1[3] = (vmat[3] = @fltdat[4]))
- vmat2[4] = (vmat1[5] = (vmat[4] = @fltdat[5]))
- vmat2[3] = -(vmat1[4] = -(vmat[5] = @fltdat[6]))
- vmat2[8] = -(vmat1[6] = (vmat[6] = @fltdat[7]))
- vmat2[7] = (vmat1[8] = (vmat[7] = @fltdat[8]))
- vmat2[6] = -(vmat1[7] = -(vmat[8] = @fltdat[9]))
-
- :def_view
- REM define the view with ref. no. 10, 11 and 12
-
- view 10, vmat[0], vmat[1], vmat[2],\
- vmat[3], vmat[4], vmat[5],\
- vmat[6], vmat[7], vmat[8]
-
- view 11, vmat1[0], vmat1[1], vmat1[2],\
- vmat1[3], vmat1[4], vmat1[5],\
- vmat1[6], vmat1[7], vmat1[8]
-
- view 12, vmat2[0], vmat2[1], vmat2[2],\
- vmat2[3], vmat2[4], vmat2[5],\
- vmat2[6], vmat2[7], vmat2[8]
-
- def = 1
- :draw
- getpos "Indicate position for torus center", def
- if (@key == -1)
- goto draw
- if (@key == -3)
- exit
- if (@key == -2)
- goto method
-
- def = @key
- x1 = @xworld
- y1 = @yworld
- z1 = @zworld
-
- call xfmwv, vmat, x1, y1, z·.╞dâ3└Ä╪í