/* CMD: flatten polygon
*/
/* by GLYPH */
call addlib("LWModelerARexx.port",0)
call addlib("rexxmathlib.library",0,-30,0)
call addlib("rexxsupport.library",0,-30,0)
pi = 3.1415926385897932384626
call GETPOINTS
if (n < 3) then return
call ROTATE(arctan(y.2-y.1,x.2-x.1),'Z',cx cy cz)
call GETPOINTS
call ROTATE(arctan(x.2-x.1,z.2-z.1),'Y',cx cy cz)
call GETPOINTS
call ROTATE(arctan(y.3-y.2,x.3-x.2),'Z',cx cy cz)
return
ARCTAN:
parse arg nu,de
if de = 0 then do
actn = 999999999
if nu < 0 then actn = -999999999
end
if ~(de = 0) then actn = nu/de
actu = actn
if actu < -1 then th = pi/2+atan(1/abs(actn))
if (actu < 1.00001)&(actu > -1.00001) then th = atan(actn)
if actu > 1 then th = pi/2-atan(1/actn)
return th*180/pi
GETPOINTS:
cx = 0;cy=0;cz=0
n = xfrm_begin()
do i=1 to n
tmp = xfrm_getpos(i)
parse var tmp x.i y.i z.i
cx = cx + x.i; cy = cy + y.i; cz = cz + z.i
end i
call xfrm_end()
cx = cx/n; cy = cy/n; cz = cz/n
return
               (
geocities.com/g_fyffe)