Quote: "That's really cool. Would you mind sharing your source too?"
Thanks, here is the source, sorry that took so long, I kind of forgot about this thread. It is a bit hard to figure out though, and I don't remember exactly how it works, but I could try to comment it if anyone wants. The integration part is a bit ugly though (at the bottom)
global Window
global Tabs
global Label0
global Label1
global Label2
global Label3
global Label4
global Label5
global Edit0
global Edit1
global Edit2
global Edit3
global Edit4
global Edit5
global Ok
global SidesEdit
global StepsEdit
global SidesLabel
global StepsLabel
global StartEdit
global EndEdit
global StartLabel
global EndLabel
startBlue "", ""
createUI()
disable escapekey
autocam off
type vertice
x as float
y as float
z as float
nx as float
ny as float
nz as float
endtype
dim vertices(-1) as vertice
global p0 as float
global p1 as float
global p2 as float
global p3 as float
global p4 as float
global p5 as float
global steps as float = 1.0
global sides as integer = 5
global maxY as float = 0.0
global maxZ as float = 0.0
global start as float = 0.0
global finish as float = 3.0
dim coords1(-1) as vertice
dim coords2(-1) as vertice
dim endFace(-1) as vertice
global x1 as float
global y1 as float
global x2 as float
global y2 as float
global h1 as float
global h2 as float
load image "Grid2a.png", 2
draw to back
draw sprites first
backdrop off
set camera range 0, 3000
volume as float
inkey as string
do
paste image 2, 0, 0
getEvent
if eventSource() = Ok and eventType() = MOUSE_CLICK
getData()
render()
endif
if eventSource() = Window and eventType() = WINDOW_CLOSE then end
if object exist(1) and screen fps() <> 0
inkey= inkey$()
if inkey = "+" then move camera 1/6.0 *(60.0/screen fps())
if inkey = "-" then move camera -1/6.0 *(60.0/screen fps())
EZro_Set object angle x(1), object angle y(1), object angle z(1)
if leftkey() or rightkey() then EZro_GY (rightkey()-leftkey())*2*(60.0/screen fps())
if upkey() or downkey() then EZro_GX (upkey()-downkey())*2*(60.0/screen fps())
rotate object 1, EZro_GetX(), EZro_GetY(), EZro_GetZ()
volume = (sides/(4*tan(180/sides)))*(integral(finish)-integral(start))
text 0, 0, "Volume by Cross Sections: " + str$(volume)
text 0, 466, "Use the Arrow Keys to Spin the Object, + and - to Zoom"
endif
loop
function render()
maxY = 0
maxZ = 0
empty array vertices(0)
i as float
for i = start to finish - steps + 0.000001 step steps
empty array coords1(0)
empty array coords2(0)
x1 = i
y1 = f(x1)/2.0/tan(360.0/(2*sides))
h1 = sqrt(f(x1)*f(x1)/4 + y1*y1)
x2 = i + steps
y2 = f(x2)/2.0/tan(360.0/(2*sides))
h2 = sqrt(f(x2)*f(x2)/4 + y2*y2)
angle as float
for angle = 1.0*(-90 + 360/(2*sides)) to 1.0*(270+360/(2*sides)) step 360.0/sides
array insert at bottom coords1(0)
coords1().x = x1
coords1().y = y1 + h1*sin(angle)
coords1().z = f(x1)/2 + h1*cos(angle)
array insert at bottom coords2(0)
coords2().x = x2
coords2().y = y2 + h2*sin(angle)
coords2().z = f(x2)/2 + h2*cos(angle)
next angle
x1 = start
y1 = f(x1)/2.0/tan(360.0/(2*sides))
h1 = sqrt(f(x1)*f(x1)/4 + y1*y1)
empty array endFace(0)
angle as float
for angle = 1.0*(-90 + 360/(2*sides)) to 1.0*(270+360/(2*sides)) step 360.0/sides
array insert at bottom endFace(0)
endFace().x = x1
endFace().y = y1 + h1*sin(angle)
endFace().z = f(x1)/2 + h1*cos(angle)
next angle
for a = 2 to sides-1
v1 as vertice
v1 = endFace(1)
v2 as vertice
v2 = endFace(a)
v3 as vertice
v3 = endFace(a+1)
addFace(v1, v2, v3)
next a
x1 = finish
y1 = f(x1)/2.0/tan(360.0/(2*sides))
h1 = sqrt(f(x1)*f(x1)/4 + y1*y1)
empty array endFace(0)
angle as float
for angle = 1.0*(-90 + 360/(2*sides)) to 1.0*(270+360/(2*sides)) step 360.0/sides
array insert at bottom endFace(0)
endFace().x = x1
endFace().y = y1 + h1*sin(angle)
endFace().z = f(x1)/2 + h1*cos(angle)
next angle
for a = 2 to sides-1
v1 as vertice
v1 = endFace(1)
v2 as vertice
v2 = endFace(a)
v3 as vertice
v3 = endFace(a+1)
addFace(v1, v3, v2)
next a
for b = 0 to array count(coords1(0)) - 1
va as vertice
va.x = coords1(b).x
va.y = coords1(b).y
va.z = coords1(b).z
vb as vertice
vb.x = coords2(b).x
vb.y = coords2(b).y
vb.z = coords2(b).z
vc as vertice
vc.x = coords2(b+1).x
vc.y = coords2(b+1).y
vc.z = coords2(b+1).z
vd as vertice
vd.x = coords1(b+1).x
vd.y = coords1(b+1).y
vd.z = coords1(b+1).z
addFace(va, vb, vc)
addFace(vc, vd, va)
next b
next i
makeObject()
position camera 0, 0, -20
point camera 0, 0, 0
endfunction
function addFace(va as vertice, vb as vertice, vc as vertice)
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
set vector3 1, va.x, va.y, va.z
set vector3 2, vb.x, vb.y, vb.z
set vector3 3, vc.x, vc.y, vc.z
subtract vector3 2, 2, 1
subtract vector3 3, 3, 1
normalize vector3 2,2
normalize vector3 3,3
cross product vector3 1, 2,3
normalize vector3 1,1
addVertice(va.x, va.y, va.z, x vector3(1), y vector3(1), z vector3(1))
addVertice(vb.x, vb.y, vb.z, x vector3(1), y vector3(1), z vector3(1))
addVertice(vc.x, vc.y, vc.z, x vector3(1), y vector3(1), z vector3(1))
null = delete vector3(1)
null = delete vector3(2)
null = delete vector3(3)
endfunction
function addVertice(x as float y as float z as float, nx as float, ny as float, nz as float)
array insert at bottom vertices(0)
vertices().x = x
vertices().y = y
vertices().z = z
vertices().nx = nx
vertices().ny = ny
vertices().nz = nz
if y > maxY then maxY = y
if z > maxZ then maxZ = z
endfunction
function makeObject()
if memblock exist(1) then delete memblock 1
if mesh exist(1) then delete mesh 1
if object exist(1) then delete object 1
if object exist(1) then delete object 1
make memblock 1, 12+(array count(vertices(0))+1)*36
write memblock dword 1, 0, 338
write memblock dword 1, 4, 36
write memblock dword 1, 8, array count(vertices(0))+1
pointer as integer = 12
for i = 0 to array count(vertices(0))
write memblock float 1, pointer, vertices(i).x
write memblock float 1, pointer + 4, vertices(i).y
write memblock float 1, pointer + 8, vertices(i).z
write memblock float 1, pointer + 12, vertices(i).nx
write memblock float 1, pointer + 16, vertices(i).ny
write memblock float 1, pointer + 20, vertices(i).nz
write memblock dword 1, pointer + 24, rgb(255, 255, 0)
inc pointer, 36
next i
make mesh from memblock 1, 1
make object 1, 1, 1
offset limb 1, 0, -(start + finish)/2.0, -maxY/2.0, -maxZ/2.0
endfunction
function freeObject()
id as integer
id = 1
while object exist(id)
inc id
endwhile
endfunction id
function f(x as float)
temp as float
temp = p5*x*x*x*x*x + p4*x*x*x*x + p3*x*x*x + p2*x*x + p1*x + p0
endfunction temp
function getData
tmp as string
tmp = getGadgetText(Edit0)
if tmp = ""
p0 = 0
else
p0 = val(tmp)
endif
tmp = getGadgetText(Edit1)
if tmp = ""
p1 = 0
else
p1 = val(tmp)
endif
tmp = getGadgetText(Edit2)
if tmp = ""
p2 = 0
else
p2 = val(tmp)
endif
tmp = getGadgetText(Edit3)
if tmp = ""
p3 = 0
else
p3 = val(tmp)
endif
tmp = getGadgetText(Edit4)
if tmp = ""
p4 = 0
else
p4 = val(tmp)
endif
tmp = getGadgetText(Edit5)
if tmp = ""
p5 = 0
else
p5 = val(tmp)
endif
steps = val(getGadgetText(StepsEdit))
sides = val(getGadgetText(SidesEdit))
start = val(getGadgetText(StartEdit))
finish = val(getGadgetText(EndEdit))
endfunction
function createUI()
Window=createWindow(100,210,193,420,"Function Data",WINDOW_NORMAL,0,0,0)
Tabs=createTabs(5,5,175,215,Window)
Label0=createLabel(25,35,45,20,"x ^ 0",Tabs)
Label1=createLabel(25,65,50,20,"x ^ 1",Tabs)
Label2=createLabel(25,95,50,20,"x ^ 2",Tabs)
Label3=createLabel(25,125,50,20,"x ^ 3",Tabs)
Label4=createLabel(25,155,50,20,"x ^ 4",Tabs)
Label5=createLabel(25,185,50,20,"x ^ 5",Tabs)
Edit0=createEdit(75,35,75,20,0,Tabs)
Edit1=createEdit(75,65,75,20,0,Tabs)
Edit2=createEdit(75,95,75,20,0,Tabs)
Edit3=createEdit(75,125,75,20,0,Tabs)
Edit4=createEdit(75,155,75,20,0,Tabs)
Edit5=createEdit(75,185,75,20,0,Tabs)
SidesEdit=createEdit(80,230,75,20,0,Window)
StepsEdit=createEdit(80,260,75,20,0,Window)
StartEdit=createEdit(80,290,75,20,0,Window)
EndEdit=createEdit(80,320,75,20,0,Window)
Ok=createButton(55,355,75,25,"OK",0,Window)
SidesLabel=createLabel(30,235,50,20,"Sides",Window)
StepsLabel=createLabel(30,265,50,20,"Steps",Window)
StartLabel=createLabel(30,295,50,20,"Start",Window)
EndLabel=createLabel(30,325,50,20,"End",Window)
addTab Tabs,"Polynomial"
endfunction
function polygonArea(n as integer, s as float)
area as float
area = 0.25*n*s*s/tan(180/n)
endfunction area
function pow(x as float, p as integer)
number as float
number = 1
for a = 1 to p
number = number*x
next a
endfunction number
function integral(x as integer)
total as float
total = 0
inc total, (1/11.0)*p5*p5*pow(x,11) + (2/10.0)*p5*p4*pow(x,10) + (2/9.0)*p5*p3*pow(x,9) + (2/8.0)*p5*p2*pow(x,8) + (2/7.0)*p5*p1*pow(x,7) +(2/6.0)*p5*p0*pow(x,6)
inc total, (1/9.0)*p4*p4*pow(x,9) + (2/8.0)*p4*p3*pow(x,8) + (2/7.0)*p4*p2*pow(x,7) + (2/6.0)*p4*p1*pow(x,6) + (2/5.0)*p4*p0*pow(x,5)
inc total, (1/7.0)*p3*p3*pow(x,7) + (2/6.0)*p3*p2*pow(x,6) + (2/5.0)*p3*p1*pow(x,5) + (2/4.0)*p3*p0*pow(x,4)
inc total, (1/5.0)*p2*p2*pow(x,5) + (2/4.0)*p2*p1*pow(x,4) + (2/3.0)*p2*p0*pow(x,3)
inc total, (1/3.0)*p1*p1*pow(x,3) + (2/2.0)*p1*p0*pow(x,2)
inc total, (1/1.0)*p0*p0*pow(x,1)
endfunction total
Quote: "Volume with integration by shell method...good times. "
Yeah, but I don't really remember it anymore...