home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p068 / 4.img / TORUS.CDL < prev    next >
Encoding:
Text File  |  1989-01-04  |  6.1 KB  |  203 lines

  1. REM  @(#)CADKEY SOLIDS    torus.cdl    2.2    10/31/88
  2. rem program to draw torus in space
  3.  
  4. array vmat[9]
  5. array vmat1[9]
  6. array vmat2[9]
  7.  
  8. :radius1
  9. REM Positive radius for the torus
  10.  
  11. getflt "Radius of the torus (%f) =>", 1.0, rad1
  12. if (@key <= -2)
  13.         exit
  14. if (rad1 > 0.00001)
  15.         goto radius2
  16. pause "Invalid radius ... (Press RETURN)"
  17. goto radius1
  18.  
  19. :radius2
  20. REM Positive radius for the cross section
  21.  
  22. getflt "Radius of cross section (%f) =>", 0.5, rad2
  23. if (@key == -3)
  24.         exit
  25. if (@key == -2)
  26.         goto radius1
  27. if ((rad2 < rad1) && (rad2 > 0.00001))
  28.         goto method
  29. pause "Invalid radius ... (Press RETURN)"
  30. goto radius2
  31.  
  32. :method
  33. REM The plane of the torus can be defined by two methods. NORMAL requires the
  34. REM user to indicate two points which determine the line. The plane of the
  35. REM torus is perpendicular to this line. This option is default.
  36. REM PLANE lets the user indicate a plane for the torus.
  37.  
  38. getmenu "Choose method for defining torus plane",\
  39.         "NORMAL",\
  40.         "PLANE"
  41.  
  42. if (@key == -3)
  43.         exit
  44. if (@key == -2)
  45.         goto radius2
  46. if (@key == 2)
  47.         goto plane
  48.  
  49. def = 3
  50. :first
  51. getpos "Indicate 1st pt. along the normal", def
  52. if (@key == -1)
  53.         goto first
  54. if (@key == -3)
  55.         exit
  56. if (@key == -2)
  57.         goto method
  58.  
  59. def = @key
  60. x1 = @xworld
  61. y1 = @yworld
  62. z1 = @zworld
  63.  
  64. :second
  65. getpos "Indicate 2nd pt. along the normal", def
  66. if (@key == -1)
  67.         goto second
  68. x2 = @xworld
  69. y2 = @yworld
  70. z2 = @zworld
  71.  
  72. def = @key
  73. if (@key == -3)
  74.         exit
  75. if (@key == -2)
  76.         goto first
  77. if (@key == -1)
  78.         goto second
  79.  
  80. REM direction vector for the cone axis has to be non-zero
  81. xn = x2 - x1
  82. yn = y2 - y1
  83. zn = z2 - z1
  84.  
  85. if ((abs(xn) > 0.00001) || \
  86.     (abs(yn) > 0.00001) || \
  87.     (abs(zn) > 0.00001))
  88.         goto unit
  89.  
  90. pause "2nd pt. is coincident with 1st pt. (Press RETURN)"
  91. goto second
  92.  
  93. :unit
  94. REM Take cross product of (0, 1, 0) with the direction vector to get x axis.
  95. REM If the result is a zero vector, the dirction vector is parallel to 
  96. REM (0, 1, 0), so take direction vector cross (1, 0, 0) to get y axis. Once 
  97. REM the x axis or y axis is determined, find the remaining axis by taking
  98. REM cross of the direction vector and the axis determined, thus completing 
  99. REM the orthogonal basis
  100.  
  101. rem x axis
  102. call cross, xx, xy, xz, 0, 1, 0, xn, yn, zn
  103.  
  104. if ((abs(xx) < 0.00001) && \
  105.     (abs(xy) < 0.00001) && \
  106.     (abs(xz) < 0.00001))
  107.         goto use_x
  108.  
  109. call cross, yx, yy, yz, xn, yn, zn, xx, xy, xz
  110. goto vmatrix
  111.  
  112. :use_x
  113. call cross, yx, yy, yz, xn, yn, zn, 1, 0, 0
  114. call cross, xx, xy, xz, yx, yy, yz, xn, yn, zn
  115.  
  116. :vmatrix
  117. REM Determine the vector magnitudes and convert the orthogonal basis to a
  118. REM orthnormal basis
  119.  
  120. mn = sqrt(xn*xn + yn*yn + zn*zn)
  121. mx = sqrt(xx*xx + xy*xy + xz*xz)
  122. my = sqrt(yx*yx + yy*yy + yz*yz)
  123.  
  124. REM Define the view matrix for the new view and two othe views perpendicular
  125. REM to this view (for drawing the cross section circles). Then goto defining
  126. REM these views  
  127.  
  128. vmat2[2] = -(vmat1[0] =  (vmat[0] = xx/mx))
  129. vmat2[1] =  (vmat1[2] =  (vmat[1] = yx/my))
  130. vmat2[0] = -(vmat1[1] = -(vmat[2] = xn/mn))
  131. vmat2[5] = -(vmat1[3] =  (vmat[3] = xy/mx))
  132. vmat2[4] =  (vmat1[5] =  (vmat[4] = yy/my))
  133. vmat2[3] = -(vmat1[4] = -(vmat[5] = yn/mn))
  134. vmat2[8] = -(vmat1[6] =  (vmat[6] = xz/mx))
  135. vmat2[7] =  (vmat1[8] =  (vmat[7] = yz/my))
  136. vmat2[6] = -(vmat1[7] = -(vmat[8] = zn/mn))
  137. goto def_view
  138.  
  139. :plane
  140. REM If the PLANE option is chosen, get the view matrix by GETPLANE command
  141.  
  142. getplane "Define plane for the torus", 1
  143.  
  144. if (@key == -3)
  145.         exit
  146. if (@key == -2)
  147.         goto method
  148.  
  149. getmenu "Accept plane (YES) ? ",\
  150.         "NO",\
  151.         "YES"
  152.  
  153. on (@key+3) goto exit, plane, , , plane, plmat
  154.  
  155. :plmat
  156. REM Define the view matrix for the new view and two othe views perpendicular
  157. REM to this view (for drawing the cross section circles). Then goto defining
  158. REM these views  
  159.  
  160. vmat2[2] = -(vmat1[0] =  (vmat[0] = @fltdat[1]))
  161. vmat2[1] =  (vmat1[2] =  (vmat[1] = @fltdat[2]))
  162. vmat2[0] = -(vmat1[1] = -(vmat[2] = @fltdat[3]))
  163. vmat2[5] = -(vmat1[3] =  (vmat[3] = @fltdat[4]))
  164. vmat2[4] =  (vmat1[5] =  (vmat[4] = @fltdat[5]))
  165. vmat2[3] = -(vmat1[4] = -(vmat[5] = @fltdat[6]))
  166. vmat2[8] = -(vmat1[6] =  (vmat[6] = @fltdat[7]))
  167. vmat2[7] =  (vmat1[8] =  (vmat[7] = @fltdat[8]))
  168. vmat2[6] = -(vmat1[7] = -(vmat[8] = @fltdat[9]))
  169.  
  170. :def_view
  171. REM define the view with ref. no. 10, 11 and 12
  172.  
  173. view 10, vmat[0], vmat[1], vmat[2],\
  174.          vmat[3], vmat[4], vmat[5],\
  175.          vmat[6], vmat[7], vmat[8]
  176.  
  177. view 11, vmat1[0], vmat1[1], vmat1[2],\
  178.          vmat1[3], vmat1[4], vmat1[5],\
  179.          vmat1[6], vmat1[7], vmat1[8]
  180.  
  181. view 12, vmat2[0], vmat2[1], vmat2[2],\
  182.          vmat2[3], vmat2[4], vmat2[5],\
  183.          vmat2[6], vmat2[7], vmat2[8]
  184.  
  185. def = 1
  186. :draw
  187. getpos "Indicate position for torus center", def
  188. if (@key == -1)
  189.         goto draw
  190. if (@key == -3)
  191.         exit
  192. if (@key == -2)
  193.         goto method
  194.  
  195. def = @key
  196. x1 = @xworld
  197. y1 = @yworld
  198. z1 = @zworld
  199.  
  200. call xfmwv, vmat, x1, y1, z·.╞dâ3└Ä╪í úí"úíLú íNú╕{ú ╕ÅúLî╚ú"úN√δÉ3└Ä╪î╚Ä└╛|┐╣Gⁿ≤ñ3└Ä└î╚Ä╪í@3╥Φò■╗|╣Q░Φ╪■s    ┤═âYΓ±═Ω|. ≡u.■≥═ü╧═é╩√Çⁿu'.â>≡v .Ç>≥0uΘ÷┬Çu÷┴└u
  201. DzuÇ■t.Θï.÷≤¬t#.:⌠uε.:6⌡uτ.:.≈uα.■Ou┘.╞P ÉPSQRVî╚Ä╪Ä└Ç>P uΦQr?δ>ÉêJìóΦV■r/ïç>=╦<u÷JÇt ╞≤¬δÉΦσ÷JÇuΦprδÉΦ{rÉ^ZY[X═â╩╞O╞PêJìóΦ■ü┐>╦<t╞≤├Ç>Qwtïç≡≡á≥≥╞Qwí≡ëç≡á≥êç≥ïç⌡ú?ïç≈úA░ìóΦƲ╞≤¬├í=v-H3╥ú@Φ(²░ìóΦr²rí@3╥-Φr ΦFr╞≤¬°├∙├búBëDΦ⌠ⁿ÷JÇu╞Q╞Oì░Φ-²╞Qw├╕@÷6ó⌡Çⁿt■⌡í ▒ ÷±è╚í÷±ï╪í÷&╪ëúí+├è3╥2φ≈±ú≥╣#Φ
  202. â·u■⌠á⌠:⌡uδÉ╞⌠A;≥u▄∙├ΦI■╚u°Aëí°├F Θâíúƒ3╥ΦAⁿìóíΦåⁿrµΦ^ rßìóíΦyⁿr╒íƒ3╥ΦⁿìóíΦaⁿr╜íí-3╥÷&úΦ√■r.ìóΦcⁿr%íBïDâ╥ú@Φ█√ìó░Φ%ⁿrΦr°├∙├ì6ì>óì∙ⁿ≤ñìó╞çd╟ç≡╞ç≥÷JÇu╞ç≤δÉ╞ç≤¬ïç3╥Φç√░ìóΦ╤√├Qì6óï┘╤π┘╤δï≈┴t▒╙ΩüΓ Y├Qì6óï┘╤π┘╤δï≈┴t üΓü╩p δ    ÉüΓ≡ü╩≈ëY├.╞d·3└Ä╪í$úí&ú
  203. ╕èú$î╚ú&íú íú"í úLíúN√î╚Ä╪Ä└-úbÇ>≤tè⌠êJìóΦH√Φ±┤═┤═╕╣║O╗═┤╖║═