05-02-2022, 11:16 PM
A simple 3D example showing an animated plot of a hyperboloid. Demonstrates perspective projection and rotation, I often use this program as a reference when I want to plot a 3D shape
Code: (Select All)
dim shared pi
pi = 4*atn(1)
const d = 700
const z0 = 2500
const sw = 640
const sh = 480
rr = 500
h = 1200
screen 12
do
for t=0 to h step 10
cls
hyperb rr, t, 0, 0
_display
_limit 100
next
for b=0 to 0.80*pi/2 step 0.008
cls
hyperb rr, h, b, 0
_display
_limit 100
next
_delay 0.5
for rot = 0 to 0.9*pi/2 step 0.01
cls
hyperb rr, h, 0.80*pi/2, rot
_display
_limit 100
next
_delay 0.5
for i=0 to 1 step 0.005
cls
hyperb rr, h, (1 - i)*0.80*pi/2, (1 - i)*0.9*pi/2
_display
_limit 100
next
for t=0 to h step 10
cls
hyperb rr, h-t, 0, 0
_display
_limit 100
next
loop
system
'radius, height, twist, rotate
sub hyperb (r, h, b, rot)
a = 0
x = r*cos(a - b)
z = r*sin(a - b)
y = -h/2 + 200
yy = y*cos(rot) - z*sin(rot)
zz = y*sin(rot) + z*cos(rot)
y = yy
z = zz
ox = x
oz = z
oy = y
x = r*cos(a + b)
z = r*sin(a + b)
y = h/2 + 200
yy = y*cos(rot) - z*sin(rot)
zz = y*sin(rot) + z*cos(rot)
y = yy
z = zz
oxx = x
oyy = y
ozz = z
for a = 2*pi/30 to 2*pi step 2*pi/30
x = r*cos(a - b)
z = r*sin(a - b)
y = -h/2 + 200
yy = y*cos(rot) - z*sin(rot)
zz = y*sin(rot) + z*cos(rot)
y = yy
z = zz
pset (sw/2 + ox*d/(oz + z0), sh/2 - 50 + oy*d/(oz + z0))
line -(sw/2 + x*d/( z + z0), sh/2 - 50 + y*d/( z + z0))
ox = x
oy = y
oz = z
x = r*cos(a + b)
z = r*sin(a + b)
y = h/2 + 200
yy = y*cos(rot) - z*sin(rot)
zz = y*sin(rot) + z*cos(rot)
y = yy
z = zz
line -(sw/2 + x*d/( z + z0), sh/2 - 50 + y*d/( z + z0))
line -(sw/2 + oxx*d/(ozz + z0), sh/2 - 50 + oyy*d/(ozz + z0))
oxx = x
oyy = y
ozz = z
next
end sub