home *** CD-ROM | disk | FTP | other *** search
- REM @(#)CADKEY SOLIDS sphere.cdl 2.2 10/31/88
- REM program to draw sphere entity
-
- REM define view matrices for view 1, 2 and 5
-
- array vmat1[9] = {
- 1, 0, 0, 0, 1, 0, 0, 0, 1
- }
- array vmat2[9] = {
- 1, 0, 0, 0, 0, -1, 0, 1, 0
- }
- array vmat5[9] = {
- 0, 0, 1, 1, 0, 0, 0, 1, 0
- }
-
- def = 1
-
- :radius
- REM Positive radius for the sphere
-
- getflt "Enter radius (%f) =>", 1, rad1
- if (@key <= -2)
- exit
- if (rad1 > 0.00001)
- goto sections
- pause "Invalid radius ... (Press RETURN)"
- goto radius
-
- :sections
- REM Number of latitudinal circles in the sphere
-
- getint "Enter no. of transverse sections (%d) =>", 7, sect
- if (@key == -3)
- exit
- if (@key == -2)
- goto radius
- if (sect >= 2)
- goto pos
- pause "Invalid number of sections ... (Press RETURN)"
- goto sections
-
- :pos
- getpos "Indicate center", def
- if (@key == -1)
- goto pos
- if (@key == -3)
- exit
- if (@key == -2)
- goto sections
-
- def = @key
- x1 = @xworld
- y1 = @yworld
- z1 = @zworld
-
- REM define view 1, 2 and 5 to draw the circles in these views. The latitudes
- REM are drawn in view 1, one circle in view 2 and one in view 5.
-
- view 1, 1, 0, 0, 0, 1, 0, 0, 0, 1
- view 2, 1, 0, 0, 0, 0, -1, 0, 1, 0
- view 5, 0, 0, 1, 1, 0, 0, 0, 1, 0
-
- call xfmwv, vmat1, x1, y1, z1, xc, yc, zc
-
- REM Increment the total group number and check for overflow
-
- ptot = ptot + 1
- IF (ptot > 128)
- goto overflow
-
- REM Name and make the group.
-
- sprint $grp, "_sph%d", ptot
- group $grp, ptot, 2
-
- inc = 180/sect
- i = 0
-
- :loop
- i = i+1
- if (i >= sect)
- goto lat
- diff = rad1 * cos(i*inc)
- rad2 = sqrt(rad1*rad1 - diff*diff)
- circle xc, yc, zc+diff, rad2, 1,,,, ptot, 1
- goto loop
-
- :lat
- call xfmwv, vmat2, x1, y1, z1, xc, yc, zc
- circle xc, yc, zc, rad1, 2,,,, ptot, 1
-
- call xfmwv, vmat5, x1, y1, z1, xc, yc, zc
- circle xc, yc, zc, rad1, 5,,,, ptot, 2
- goto pos
-
- :overflow
- pause "Group overflow ... Abnormal termination"
- abort
-
- :exit
- exit
-