Post by tsh73 on Nov 5, 2022 20:07:26 GMT
Got problems with
Float underflow exception
Just try n=300. Or 3000.
Then change to 301...
Float underflow exception
Just try n=300. Or 3000.
Then change to 301...
global width, minX, maxX, height, minY, maxY
nomainwin
open "Maple Leaf" for graphics as #grFunc
print #grFunc, "trapclose [trapcloseLabel]"
print #grFunc, "home ; down ; posxy x y"
'x, y give us width, height
width = 2*x : height = 2*y
pi = acs(-1)
'parametric plot
t0=0
tk=1*pi
'nPoints
n = 300 'give FloatUnderflowException,
'our y(t) function catcher it but we got vertical lines to 0
n = 3000 'looks better but these vertical lines not supposed be there, are they?
n = 301 'this small change just never steps on these problem points
h = (tk-t0)/n
'get x, y bounds
a = 1e10
b = -1e10
minY = 1e10
maxY = -1e10
for t = t0 to tk step h
x = x(t)
if x< a then a = x
if x> b then b = x
y = y(t)
if y< minY then minY = y
if y> maxY then maxY = y
next
minX = a : maxX = b
'print "ymin, ymax ", minY, maxY
'axes
xxmin = sx(a) : xxmax = sx(b) : y0 = sy(0)
print #grFunc, "line ";xxmin;" ";y0;" "; xxmax;" ";y0 'horiz from A to B
print #grFunc, "place ";xxmax-15;" ";y0-5
print #grFunc, "\X"
yymin = sy(minY) : yymax = sy(maxY) : x0 = sx(0)
print #grFunc, "line ";x0;" ";yymin;" "; x0;" ";yymax 'vert ymin to ymax
print #grFunc, "place ";x0-15;" ";yymax+15
print #grFunc, "\Y"
x = sx(x(t0))
y = sy(y(t0))
print #grFunc, "place ";x;" ";y
for t = t0 to tk step h
y = sy(y(t))
xx = sx(x(t))
print #grFunc, "goto "; xx; " "; y
next
print #grFunc, "flush"
wait
end
[trapcloseLabel]
close #grFunc
end
'******************************************
'sample function
function x(t)
on error goto [catch]
'x = 100*cos(t)
x = (1+cos(6*t)^2 +1/5*(cos(6*t)*cos(24*t))^10 + _
(1/4*cos(30*t)^2+1/9*cos(30*t)^12) *(1-sin(6*t)^10) _
) *sin(2*t)*(1-cos(t)^4)* _
(1-cos(t)^10*cos(3*t)^2 ) +1/70*cos(t)^9
exit function
[catch]
if Err$="Float underflow exception" then y = 0: exit function
'else die
print Err, Err$
end
end function
function y(t)
on error goto [catch]
'y = 130*sin(3*t)
y = 0-21/20*cos(2*t)*(1-cos(t)^4+1/2*(cos(t)*cos(3*t))^10) * _
(1+cos(6*t)^2+1/5*(cos(6*t)*cos(18*t))^10 + _
(1/4*cos(30*t)^4 +1/10 * cos(30*t)^12 ) * _
(1-cos(t)^10*cos(3*t)^2 ) *(1-sin(6*t)^10) _
)
exit function
[catch]
if Err$="Float underflow exception" then y = 0: exit function
'else die
print Err, Err$
end
end function
'conversions (logical coords to screen)
function sx(x)
'screen X. Depends on width, minX, maxX
sx = (x- minX)/(maxX-minX) * width
end function
function sy(y)
'screen Y. Depends on height, minY, maxY. Upside down.
sy = (1-(y- minY)/(maxY-minY)) * height
end function