home *** CD-ROM | disk | FTP | other *** search
Wrap
/* Written by Don Cox, May 94. Copyright. Not Public Domain. */ /* $VER: Spirals.pdrx May 94 */ trace n units = pdm_GetUnits() if units = 3 then call pdm_SetUnits(1) if show("l", "gdarexxsupport.library") then if ~remlib("gdarexxsupport.library") then call pdm_Inform(1,"Could not remove gdarexxsupport.library - curves may be faulty","Resume") /* rexxmathlib.library is needed to work around the square root bug in gdarexxsupport.library */ if ~show("l", "rexxmathlib.library") then if ~addlib("rexxmathlib.library", 0, -30,0) then do call ppm_Inform(1,"Please install the rexxmathlib.library in your libs: directory before running this Genie.") end numeric digits 14 pi = 3.141593 pi2 = 6.28318 cr = '0a'x CurveRadius = 1.0 points = getclip(pduserpolypoints) radius = getclip(pduserpolyradius) outer = getclip(pduserpolyouter) if points = '' then points = 100 if radius = '' then radius = 2 if outer = '' then outer = 0.1 spirallist = "Evolute"||cr||"Archimedean"||cr||"Logarithmic"||cr||"Spherical" spiraltype = pdm_SelectFromList("Select spiral type",19,4,0,spirallist) if spiraltype = "" then exit_msg("No spiral type selected") select when spiraltype = "Evolute" then do paramstring = "Circle radius:"radius ||cr|| "Points:"points params = pdm_GetForm("Enter parameters",8, paramstring) if params = '' then exit_msg("Aborted by User") parse var params radius '0a'x npoints npoints = strip(npoints) radius = strip(radius) if ~(datatype(radius, n) & datatype(npoints, n)) then exit_msg("Invalid Entry") if npoints < 3 then exit_msg("A spiral must have at least 3 points") npoints = abs(npoints) radius = abs(radius) diameter = radius*2 end when spiraltype = "Archimedean" then do paramstring = "Start radius:"radius ||cr|| "Points:"points params = pdm_GetForm("Enter parameters",8, paramstring) if params = '' then exit_msg("Aborted by User") parse var params radius '0a'x npoints npoints = strip(npoints) radius = strip(radius) if ~(datatype(radius, n) & datatype(npoints, n)) then exit_msg("Invalid Entry") if npoints < 3 then exit_msg("A spiral must have at least 3 points") npoints = abs(npoints) radius = abs(radius) diameter = radius*2 end when spiraltype = "Logarithmic" then do paramstring = "Start radius:"radius ||cr|| "Points:"points ||cr|| "Growth factor:"outer params = pdm_GetForm("Enter parameters",8, paramstring) if params = '' then exit_msg("Aborted by User") parse var params radius '0a'x npoints '0a'x outer npoints = strip(npoints) radius = strip(radius) if ~(datatype(radius, n) & datatype(npoints, n) & datatype(outer,n)) then exit_msg("Invalid Entry") if npoints < 3 then exit_msg("A spiral must have at least 3 points") npoints = abs(npoints) radius = abs(radius) diameter = radius*2 outer = abs(outer) end when spiraltype = "Spherical" then do paramstring = "Start radius:"radius ||cr|| "Slope factor:"outer ||cr|| "Points:"points params = pdm_GetForm("Enter parameters",8, paramstring) if params = '' then exit_msg("Aborted by User") parse var params radius '0a'x outer '0a'x npoints npoints = strip(npoints) radius = strip(radius) if ~(datatype(radius, n) & datatype(npoints, n) & datatype(outer,n)) then exit_msg("Invalid Entry") if npoints < 3 then exit_msg("A spiral must have at least 3 points") npoints = abs(npoints) radius = abs(radius) diameter = radius*2 outer = abs(outer) end end call setclip(pduserpolypoints, npoints) call setclip(pduserpolyradius, radius) call setclip(pduserpolyouter, outer) posn = pdm_GetClickPosn("Click at position for spiral..") if posn = '' then exit_msg() xpos = word(posn,1) ypos = word(posn,2) call pdm_ShowStatus("Working..") select when spiraltype = "Evolute" then do circle = pdm_DrawEllipse(xpos, ypos, diameter, diameter) call pdm_initplot(xpos+radius, ypos,1,1,0) do N = 0 to npoints+1 T=2*pi*N/10 x = radius * (cos(T) + T*sin(T)) y = radius * (sin(T) - T*cos(T)) call pdm_PlotSmooth(x" "y) end object = pdm_endplot() call pdm_RemovePoint(object,npoints+1) /* Tangents are wrong on last point drawn */ call pdm_SelectObj(circle,object) end when spiraltype = "Archimedean" then do call pdm_initplot(xpos, ypos,1,1,0) do N = 0 to npoints+1 R = radius * N/4 /* divide by 4 to get closer spacing, smoother curves */ x = R * cos(N/4) y = R * sin(N/4) call pdm_PlotSmooth(x" "y) end object = pdm_endplot() call pdm_RemovePoint(object,npoints+1) call pdm_SelectObj(object) end when spiraltype = "Logarithmic" then do call pdm_initplot(xpos, ypos,1,1,0) do N = 0 to npoints+1 R = radius * exp(outer*N/4) x = R * cos(N/4) y = R * sin(N/4) call pdm_PlotSmooth(x" "y) end object = pdm_endplot() call pdm_RemovePoint(object,npoints+1) call pdm_SelectObj(object) end when spiraltype = "Spherical" then do call pdm_initplot(xpos, ypos,1,1,0) P = 1/sqrt(2) Q = P* sqrt(1-outer*outer) /* projection constants */ do N = trunc(0-(npoints/2)) to (npoints/2)+1 S = N*pi/20 T = atan(radius*S) X = cos(S) * cos(T) Y = sin(S) * cos(T) Z = -sin(T) U = P*(Y-X)*4 V = (outer*Z-Q*(X+Y))*4 call pdm_PlotSmooth(U" "V) end object = pdm_endplot() call pdm_RemovePoint(object,npoints+1) call pdm_SelectObj(object) end otherwise exit_msg("Spiral type not supported") end object = pdm_SelectObj(object) call pdm_UpdateScreen(1) exit_msg() exit_msg: procedure expose units do parse arg message if message ~= '' then call pdm_Inform(1,message,) call pdm_ClearStatus() call pdm_SetUnits(units) call pdm_AutoUpdate(1) exit end