We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Intersection of 2 tridimensional shapes
Page Index Toggle Pages: 1
Intersection of 2 tridimensional shapes (Read 1218 times)
Intersection of 2 tridimensional shapes
Oct 29th, 2008, 3:58pm
 
Hi,
I am not an expert in processing-opengl so I need an help to
solve this problem: I want to draw a tridimensional figure
that corresponds to the intersection of 2 spheres of equal
radius.

How can I do? Is there some function that taken two tridimensional shapes can do the subtraction pixel to pixel
in order to keep only the point that appartain to both the
figures?

Thanks in advance
Re: Intersection of 2 tridimensional shapes
Reply #1 - Oct 29th, 2008, 6:33pm
 
take the distance between the 2 spheres center point and check it against the sum of their radius


pseudo code:

Vector3 v = sphere1.pos - sphere2.pos;
distance = sqrt( v.x*v.x + v.y*v.y + v.z*v.z );

if( distance <= (sphere1.radius+sphere2.radius) )
 // it collides
else
 // there is no collision... yet
Re: Intersection of 2 tridimensional shapes
Reply #2 - Oct 29th, 2008, 7:16pm
 
Hi,
thank you for answearing.

My question is how can I draw the shape resulting
from the intersection!

---------------------------------------
That is, thenew pseudo code should be:

Vector3 v = sphere1.pos - sphere2.pos;
distance = sqrt( v.x*v.x + v.y*v.y + v.z*v.z );

if( distance <= (sphere1.radius+sphere2.radius) )
 // it collides
DRAW THE SHAPE RESULTING FROM THE INTERSECTION OF
THE 2 SPHERES.
else
 // there is no collision... yet

------------------------------------------

Can anyone help me?

Thanks in advance
Re: Intersection of 2 tridimensional shapes
Reply #3 - Oct 29th, 2008, 8:15pm
 
ok i misunderstood your question.

you might wanna look into CSG:
http://en.wikipedia.org/wiki/Constructive_solid_geometry

this for the sphere, for the 2d version it might get simpler as you can go thru the screen pixels and check which ones are intersecting with 2 circles, not 2 spheres.

if the pixel is within range for both circles, it means its part of the intersecting area
Re: Intersection of 2 tridimensional shapes
Reply #4 - Oct 29th, 2008, 8:53pm
 
Ok thanks a lot.

Now I study.

But just to have some initial hints could you please post a
processing code that implements the intersection part of
the 2 spheres?

Maybe it could be useful for someone else?.

Thanks in advance
Re: Intersection of 2 tridimensional shapes
Reply #5 - Oct 29th, 2008, 11:27pm
 
there are lots of useful google answers for 'intersection of two spheres'

http://ozviz.wasp.uwa.edu.au/~pbourke/geometry/spheresphere/

http://mathworld.wolfram.com/Sphere-SphereIntersection.html

and this was my initial idea (translate and rotate to origin and x-axis, work out intersection, transform back):

http://groups.google.com/group/geometry.research/browse_thread/thread/91949d443dc20352/de47e0e2aacc54e8

actual intersection solid is a symmetrical, circular lens shape of thickness 2r-d at its centre and with a radius given by the above.
Re: Intersection of 2 tridimensional shapes
Reply #6 - Oct 30th, 2008, 12:11am
 
Hi,
really thanks for answearing.

Atually I do not want exactly the intersection of 2 spheres, but the intersection of 7 spheres in order to draw in 3D the figure called "Seed of Life" (see http://mathworld.wolfram.com/SeedofLife.html).

I want to extend such a 2D figure to 3D, where each petal is placed in the 6 directions of the 3 cartesian axes.

Maybe the right solution is using CSG. What do you think?

Has someone some suggestion that can put light on the
matter?

...I am a little in truble...Help!
Page Index Toggle Pages: 1