**3**

# Intersection of two 3D Polyhedrons

Started by sgdimitris, Mar 12 2012 05:56 AM

16 replies to this topic

###
#1
Members - Reputation: **100**

Posted 12 March 2012 - 05:56 AM

Hello to all users,

I'm making a project for my university and I need to calculate the intersection of two given 3D polyhedrons. How can I do that?

I know the x,y,z, coordinates of each vertex and also the triangles list that I use to draw each polyhedron.

Any help would be very very appreciated.

With regard,

Dimitris

I'm making a project for my university and I need to calculate the intersection of two given 3D polyhedrons. How can I do that?

I know the x,y,z, coordinates of each vertex and also the triangles list that I use to draw each polyhedron.

Any help would be very very appreciated.

With regard,

Dimitris

###
#2
Members - Reputation: **295**

Posted 12 March 2012 - 07:00 AM

This should work:

-Create from all the edges of your polyhedron Rays (make sure that the rays are not infinite, but have the length of the tested edge),

-Intersect them with all triangles of polyhedron.

Ray to Triangle intersection: http://www.softsurfe...orithm_0105.htm

Perhaps not the best approach, but it should work.

Good luck

-Create from all the edges of your polyhedron Rays (make sure that the rays are not infinite, but have the length of the tested edge),

-Intersect them with all triangles of polyhedron.

Ray to Triangle intersection: http://www.softsurfe...orithm_0105.htm

Perhaps not the best approach, but it should work.

Good luck

###
#5
Members - Reputation: **2409**

Posted 12 March 2012 - 09:07 AM

I want the polyhedron, not only check

General polyhedron intersection is a very broad and complex problem, made even more complex when accounting for floating point inaccuracy. There's various libraries around with different characteristics. It gets even more complex if allowing degenerate and self-intersecting inputs.

Such operations are typically performed using CSG and polyhedra are only generated as final step. One disadvantage of such approach is that polyhedra aren't perfect fit, so there might be intersections left as result.

One way is to work on triangle soup. Intersect triangles, then run a post-processing pass to reconstruct final result. Quite a few simplifications can be made if limiting the solution to a well-defined problem, perhaps merely generating non-intersecting objects or similar.

###
#7
Members - Reputation: **102**

Posted 14 March 2012 - 10:41 AM

On large scale multiple intersactions, won't that make the code very slow?

Of course, but you are going for general intersection. Usually you do some filtering using convex hulls or bounding boxes/convex polyhedrons, and then you use the detailed mechanism only for the intersecting bodies

###
#8
Members - Reputation: **190**

Posted 14 March 2012 - 11:27 PM

A popular way to do this is to generate a bsp tree of of your polyhedrons and then merge the trees in the appropriate way - google for BSP and CSG together to find details on how the two are used together.

If I was going to do this in a quick and dirty way, I would simply take the triangles of one of the polyhedra (the one with the fewest triangles), extend them to planes and split (look for "polyhedral splitting" - it is a well studied problem) the other polyhedron. Then all you have to do is classify the resulting small polyhedra as in or out of the polyhedron used to generate the splitting planes. This can be done with a simple point inside mesh query. Finally you take the "inside" polyhedra and work out the union of them, which isn't to hard since they share sides and don't overlap.

If I was going to do this in a quick and dirty way, I would simply take the triangles of one of the polyhedra (the one with the fewest triangles), extend them to planes and split (look for "polyhedral splitting" - it is a well studied problem) the other polyhedron. Then all you have to do is classify the resulting small polyhedra as in or out of the polyhedron used to generate the splitting planes. This can be done with a simple point inside mesh query. Finally you take the "inside" polyhedra and work out the union of them, which isn't to hard since they share sides and don't overlap.

###
#11
Members - Reputation: **190**

Posted 10 April 2012 - 12:48 AM

Sorry for the late answer, yes the polyhedra are convex

Then it's much easier: there are libraries that convert between vertex representations and hyperplane representations (and back), you just need to convert both polyhedra to hyperplane (just planes actually in 3d), take the union of these sets planes and convert it to vertex representation.

If you want a more direct approach, in 3d, you can take one polyhedron, and for each triangle, generate a plane using the triangle normal and one of it's vertices. Take these planes, and intersect it with the other polyhedron, keeping only the inside half space. Specifically, throw away all triangles whose vertices are all in the outside half space, and keep all the triangles, whose vertices are in the inside half space. Then for all the triangles that cross the plane, clip them to the inside half space. The new vertices that result from the clipped edges will now form a convex polygon embedded within the the intersection plane. Triangulate this. Repeat this for each triangle/plane of the first polyhedron, and you're done!

###
#15
Prime Members - Reputation: **699**

Posted 18 April 2012 - 11:54 AM

Hello Dimitris

If the volumes are convex, it's possible to use the Séparating Axis Theorem (SAT) method. (http://en.wikipedia.org/wiki/Hyperplane_separation_theorem)

This method is well documented. I can give you my implementation "as an example" if you wish (for what it's worth of course )

What's more with this method you can get the penetration depth if you need it.

Nico

If the volumes are convex, it's possible to use the Séparating Axis Theorem (SAT) method. (http://en.wikipedia.org/wiki/Hyperplane_separation_theorem)

This method is well documented. I can give you my implementation "as an example" if you wish (for what it's worth of course )

What's more with this method you can get the penetration depth if you need it.

Nico

###
#16
Members - Reputation: **547**

Posted 18 April 2012 - 01:43 PM

If it was calculating the intersection volume you meant (I'm not clear whether you meant this or just how far they 'poke' each other) it is probably best to google for CSG of convex hulls.

http://en.wikipedia.org/wiki/Constructive_solid_geometry

'QHull' is a library that may have an implementation to look at I believe, and also probably there is one in Dave Eberly's Geometric Tools http://www.geometrictools.com/ (he's a great egghead and has got libraries for everything lol, he wrote the NDL / gamebryo stuff).

In games the convex hulls are often known as 'brushes' and are widely used in quake derived stuff and unreal, if you have a look at dealing with their maps, or gtkradiant source you might get some ideas.

If you can valmorphanize your polygon representation into a set of planes defining the sides of a brush, you can then add planes (or their opposites) from one brush to another to split it up and do CSG jiggery pokery. Then you can use a routine to rebuild the brush from a set of planes back into a set of polygons (using e.g. the intersection of 3 planes to form a vertex) and chuck out any irrelevant planes / polys that have been clipped out by inserted planes. That's how I did it anyway.

http://en.wikipedia.org/wiki/Constructive_solid_geometry

'QHull' is a library that may have an implementation to look at I believe, and also probably there is one in Dave Eberly's Geometric Tools http://www.geometrictools.com/ (he's a great egghead and has got libraries for everything lol, he wrote the NDL / gamebryo stuff).

In games the convex hulls are often known as 'brushes' and are widely used in quake derived stuff and unreal, if you have a look at dealing with their maps, or gtkradiant source you might get some ideas.

If you can valmorphanize your polygon representation into a set of planes defining the sides of a brush, you can then add planes (or their opposites) from one brush to another to split it up and do CSG jiggery pokery. Then you can use a routine to rebuild the brush from a set of planes back into a set of polygons (using e.g. the intersection of 3 planes to form a vertex) and chuck out any irrelevant planes / polys that have been clipped out by inserted planes. That's how I did it anyway.

###
#17
Members - Reputation: **2109**

Posted 19 April 2012 - 03:30 AM

GJK (Gilbert Johnson Keerthi) is another well-known algorithm for finding the intersection or closest features of polyhedra.

EDIT: this video has a really good explanation of how it works. The forums on that site are also worth visiting to find enhancements etc.

EDIT: this video has a really good explanation of how it works. The forums on that site are also worth visiting to find enhancements etc.