How to remove the sqr() to get z ?
I know there must be a simple 2D solution
we know:
radius and radius squared both 1 (Unit Circle)
the range of x: = -1 -> 0 -> +1
the range of y: = -1 -> 0 -> +1
x squared x2 = x*x
y squared y2 = y*y
z squared z2 = 1 - (x2 + y2)
Can you help or give me a small hint I'm stupid today ?
(my mother passed away few days ago so I need some distraction)
Thank you
Joshy
Here are the code with sqr()
Code: Select all
screenres 640,480,32
dim as integer w,h
screeninfo w,h
width w/8,h/16
dim as single r = 100, r2=r*r
dim as single cx = w/2.0, cy = h/2.0
dim as single sx=2.0/w
dim as single sy=2.0/h
for y as single = -1 to 1 step sy
dim as single y2=y*y
for x as single = -1 to 1 step sx
dim as single x2=x*x
if x2 + y2 <= 1 then
dim as single z2 = 1 - (x2+y2)
'dim as single IsOne = x2 + y2 + z2
dim as single z = iif(z2,sqr(z2),0)
pset(cx + x*r,h-r + y*r),rgb(abs(x)*255,abs(y)*255,abs(z)*255)
dim as single xr=(1+x)*r
dim as single yr=(1+y)*r
pset(xr ,yr),rgb(abs(x)*255,0,0)
pset(xr+r*2,yr),rgb(0,abs(y)*255,0)
pset(xr+r*4,yr),rgb(0,0,abs(z)*255)
end if
next
next
draw string (r*0 ,r),"-1 X" : draw string (r*1-20,r)," 0 X" : draw string (r*2-32,r) ,"+1 X"
draw string (r*3-16,4),"+1 Y" : draw string (r*3-16,r)," 0 Y" : draw string (r*3-16,r*2-16),"-1 Y"
draw string (r*5-16,4)," 0 Z" : draw string (r*5-16,r),"+1 Z" : draw string (r*5-16,r*2-16)," 0 Z"
sleep
Compare both results looks not bad but I need the correct solution.
Code: Select all
screenres 640,480,32
dim as integer w,h
screeninfo w,h
width w/8,h/16
dim as single r = 100, r2=r*r
dim as single cx = w/2.0, cy = h/2.0
dim as single sx=2.0/w
dim as single sy=2.0/h
for y as single = -1 to 1 step sy
dim as single y2=y*y
for x as single = -1 to 1 step sx
dim as single x2=x*x
if x2 + y2 <= 1 then
dim as single z2 = 1 - (x2+y2)
'dim as single IsOne = x2 + y2 + z2
dim as single z = (x2+y2)-1
pset(cx + x*r,h-r + y*r),rgb(abs(x)*255,abs(y)*255,abs(z)*255)
dim as single xr=(1+x)*r
dim as single yr=(1+y)*r
pset(xr ,yr),rgb(abs(x)*255,0,0)
pset(xr+r*2,yr),rgb(0,abs(y)*255,0)
pset(xr+r*4,yr),rgb(0,0,abs(z)*255)
end if
next
next
draw string (r*0 ,r),"-1 X" : draw string (r*1-20,r)," 0 X" : draw string (r*2-32,r) ,"+1 X"
draw string (r*3-16,4),"+1 Y" : draw string (r*3-16,r)," 0 Y" : draw string (r*3-16,r*2-16),"-1 Y"
draw string (r*5-16,4)," 0 Z" : draw string (r*5-16,r),"+1 Z" : draw string (r*5-16,r*2-16)," 0 Z"
sleep