• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
sgdimitris

Intersection of two 3D Polyhedrons

16 posts in this topic

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
0

Share this post


Link to post
Share on other sites
Ray to Triangle intersection: [url="http://www.softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm"]http://www.softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm[/url]

good luck :)
0

Share this post


Link to post
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: [url="http://www.softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm"]http://www.softsurfe...orithm_0105.htm[/url]

Perhaps not the best approach, but it should work.

Good luck
1

Share this post


Link to post
Share on other sites
Do you want the polyhedron of the intersecting volume of the two original polyhedrons, or just check if they do or do not intersect?
0

Share this post


Link to post
Share on other sites
[quote name='sgdimitris' timestamp='1331560144' post='4921332']
I want the polyhedron, not only check
[/quote]

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.
0

Share this post


Link to post
Share on other sites
[quote name='darksheikh' timestamp='1331738486' post='4921996']
On large scale multiple intersactions, won't that make the code very slow?
[/quote]

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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='sgdimitris' timestamp='1333880145' post='4929271']
Sorry for the late answer, yes the polyhedra are convex
[/quote]

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!

1

Share this post


Link to post
Share on other sites
Hello Crowley99,
do you have some links that can help us implement one of the two given algorithms?
Regards,
Dimitris
0

Share this post


Link to post
Share on other sites
Hello Dimitris

If the volumes are convex, it's possible to use the Séparating Axis Theorem (SAT) method. ([url="http://en.wikipedia.org/wiki/Hyperplane_separation_theorem"]http://en.wikipedia.org/wiki/Hyperplane_separation_theorem[/url])
This method is well documented. I can give you my implementation "as an example" if you wish (for what it's worth of course [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] )

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

Nico [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img]
0

Share this post


Link to post
Share on other sites
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.

[url="http://en.wikipedia.org/wiki/Constructive_solid_geometry"]http://en.wikipedia.org/wiki/Constructive_solid_geometry[/url]

'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 [url="http://www.geometrictools.com/"]http://www.geometrictools.com/[/url] (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.
0

Share this post


Link to post
Share on other sites
GJK (Gilbert Johnson Keerthi) is another well-known algorithm for finding the intersection or closest features of polyhedra.

EDIT: [url="https://mollyrocket.com/849"]this video[/url] has a really good explanation of how it works. [url="https://mollyrocket.com/forums/viewforum.php?f=13"]The forums on that site[/url] are also worth visiting to find enhancements etc.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0