home *** CD-ROM | disk | FTP | other *** search
- /* CMD: Plot & Turn
- *
- * Plot a 1-D line function as a set of connected segments.
- * Optionally create surface of revolution by specifying start, end angles
- * by Stuart Ferguson (with trivial lathe addition by Arnie)
- * Sat May 8 16:01:54 1993
- */
-
- call addlib "LWModelerARexx.port", 0
- signal on error
- signal on syntax
-
- MATHLIB="rexxmathlib.library"
- IF POS(MATHLIB , SHOW('L')) = 0 THEN
- IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
- call notify(1,"!Can't find "MATHLIB)
- exit
- END
- call addlib "rexxsupport.library", 0, -30, 0
- sysnam = 'Plot Function'
- filnam = 'ENV:plot.state'
- version = 'Plot and Turn v1.0'
-
- /* Setup state. Read stored one, if any.
- */
- ind = 2
- dep = 1
- lo = 0
- hi = 6.3
- n = 20
- fun = "sin(x)*exp(-x/3) + 0.5 + x/"hi
- dfun= fun
- typ=2
- startangle=0
- angle=300
- sides=16
- if (exists(filnam)) then do
- if (~open(state, filnam, 'R')) then break
- if (readln(state) ~= version) then break
- parse value readln(state) with ind dep lo hi n startangle angle sides typ .
- fun = readln(state)
- call close state
- end
-
- call req_begin sysnam
-
- id_ind = req_addcontrol("Independent Axis", 'c', 'X Y Z')
- id_dep = req_addcontrol("Dependent Axis", 'c', 'X Y Z')
- id_lo = req_addcontrol("Low", 'n', 1)
- id_hi = req_addcontrol("High", 'n', 1)
- id_ns = req_addcontrol("Segments", 'n')
- id_fun = req_addcontrol("Function", 's', 35)
- StAngId = req_addcontrol("Start Angle",'N',0)
- AngId = req_addcontrol("End Angle",'N',0)
- id_sides = req_addcontrol("Sides", 'n')
- id_typ = req_addcontrol("Build: ","CH","Points Polys Curves")
-
- call req_setval id_ind, ind
- call req_setval id_dep, dep
- call req_setval id_lo, lo
- call req_setval id_hi, hi
- call req_setval id_ns, n
- call req_setval id_fun, fun, dfun
- call req_setval StAngId, startangle,0
- call req_setval AngId, angle,0
- call req_setval id_sides, sides
- call req_setval id_typ, typ,typ
-
- if (~req_post()) then do
- call req_end
- exit
- end
- req=1
- ind = req_getval(id_ind)
- dep = req_getval(id_dep)
- n = req_getval(id_ns) % 1
- lo = req_getval(id_lo)
- hi = req_getval(id_hi)
- typ = req_getval(id_typ)
- fun = req_getval(id_fun)
- startangle = req_getval(StAngId)
- angle = req_getval(AngId)
- sides = req_getval(id_sides)
- call req_end
-
- if (ind = dep) then do
- call notify 1, '@'sysnam, "!Independent and dependent
- axes must be different."
- exit
- end
-
- /* Save state now, in case something fails. */
- if (open(state, filnam, 'W')) then do
- call writeln state, version
- call writeln state, ind dep lo hi n startangle angle sides typ
- call writeln state, fun
- call close state
- end
-
- do i = 1 to 3
- if (ind = i) then cx.i = 1
- else if (dep = i) then cx.i = 2
- else cx.i = 3
- end i
- ifunc = "v =" fun
- call CUT()
- crv=""
- call add_begin
- call meter_begin n+2,'Plotting 'n' points.', ifunc
- do i = 0 to n
- x = lo + (hi - lo) * i / n
- y = x
- z = x
- interpret ifunc
-
- cvec = x v 0
- vec = word(cvec, cx.1) word(cvec, cx.2) word(cvec, cx.3)
-
- crv = crv add_point(vec)
- if (i ~= 0 & typ=2) then call add_polygon i i+1
- call meter_step
- end i
- if typ=3 then call add_curve(crv)
- say ind translate(ind,"XYZ","123")
- call meter_end
- call add_end
-
- if ( ( (startangle~=0) | (angle~=0) ) & (sides>0)) then do
- sides=((sides*(angle-startangle)/360)%1)
- call LATHE(translate(ind,"XYZ","123"),sides,0,angle,startangle)
- end
- call PASTE()
- exit
-
- syntax:
- error:
- call end_all
- t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
- exit
-