Quote: "For different sized spheres with radius 'R' and 'r', a distance of 'd' apart, the equation is:
+ Code Snippet
For spheres of the same size the equation for the volume is:
+ Code Snippet
The new radius is given by (3V/(4*pi))^(1/3) where V is the volume."
I'm trying to put the new maths in the other code to make the new sphere, but I have no idea how to do it...
rem sphere created from 2 intersecting spheres
rem by latch
rem 09/18/2011
sync on: sync rate 60
rem make a couple of spheres
make object sphere 1,40
`ghost object on 1
set object 1,0,1,1
make object sphere 2,26
`ghost object on 2
set object 2,0,1,1
rem store the radii
rad1#=20
rad2#=13
rem this 3rd sphere will be for a changing size sphere created in between the
rem intersection of the other spheres
make object sphere 3,1
color object 3,rgb(255,0,0)
hide object 3
do
gosub _move_object_sphere
gosub _intersect_test
sync
loop
_move_object_sphere:
rem move object 2 around (the smaller sphere)
if upkey() then inc y
if downkey() then dec y
if rightkey() then inc x
if leftkey() then dec x
position object 2,x,y,0
position camera x,y,-50
return
_intersect_test:
remstart
If the 2 spheres intersect (collide) then figure out the diameter of the
area perpedicular to the collison normal (the little ellipse like thing created
between the spheres) - i.e. the diameter lined up with the spheres radii
remend
rem first find the distance between the spheres radii
dx#=object position x(1)-object position x(2)
dy#=object position y(1)-object position y(2)
dz#=object position z(1)-object position z(2)
dist#=sqrt((dx#*dx#)+(dy#*dy#)+(dz#*dz#))
rem if the distance < the sum of the radii, the spheres are intersecting
sumofradii#=rad1#+rad2#
if dist# < sumofradii#
rem it's true, the spheres are intersecting. Now subtract dist# from sumofradii# .
rem That will give us the diameter of the intersecting area. For a DarkBASIC
rem sphere, that's all we need
diameter#=sumofradii#-dist#
rem half of the diameter is the radius - we'll use this later
`rad3#=diameter#/2.0
`**************************************************************
`I just jammed this in here for now, but 2dr 2dR etc confuse me.
pi*(Rad1+rad2-dist#)²*(dist#²+2dr-3rad2²+2dR+6rR-3Rad1²)/(12dist#)
`*****************************************************************
rem resize sphere 3
sc#=100*diameter#
scale object 3,sc#,sc#,sc#
rem position the sphere in between the other spheres
oldx#=object angle x(3)
oldy#=object angle y(3)
oldz#=object angle z(3)
rem move the sphere the length of one of the radii minus it's own radius
position object 3,object position x(1),object position y(1),object position z(1)
point object 3,object position x(2),object position y(2),object position z(2)
move object 3,rad1#-rad3#
rem reorient the sphere
rotate object 3,oldx#,oldy#,oldz#
rem make the 3rd sphere visible
if object visible(3)=0
show object 3
endif
else
rem the spheres aren't intersecting, hide object 3 if visible
if object visible(3)
hide object 3
endif
endif
return
