• 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 CONVEX polyhedrons

9 posts in this topic

Hello to all users,
I need to calculate the intersection of two given [u][b]CONVEX[/b][/u] 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 regards,
Dimitris
0

Share this post


Link to post
Share on other sites
What you're talking about here is called CSG or [url="http://en.wikipedia.org/wiki/Constructive_solid_geometry"]Constructive Solid Geometry[/url]. The standard solution (and as best I can tell after a fair amount of research also simplest and [i]generally[/i] fastest) to this is David Laidlaw's [url="http://www.cs.brown.edu/~jfh/papers/Laidlaw-CSG-1986/paper.pdf"]paper[/url]. Note, however, that this is a seemingly simple algorithm that is very tough to debug and will likely take you weeks if not months to implement properly and efficiently (I spent weeks on polygon merging and postprocessing to minimized geometric clutter alone). There is no specialized approach for convex polyhedra that I know of - CSG handles all [i][b]closed[/b] convex and concave[/i] polyhedra of any complexity and gives you same-cost access to all intersection modes: intersection (common volume), union (joint volume) and subtraction (A - B or B - A). Note, though, that one thing you can probably optimize a fair bit is your poly intersection code, which can be generalized if you know your meshes are convex. At the end of the day it's probably easiest to pick up a CSG library, but sadly I can't suggest any to you as I didn't end up trying out any.

Note that if you can get away with an estimate (eg for collision), then I suggest calculating the AABB/sphere of the [i]common volume[/i]: raycast all points of A through B and all points of B through A. All points of either object that fall inside the other object form the bounding box of the shared volume (just calculate the extents). You can use your favourite convex hull method to extend this to a shape of any complexity.

Hope this helps.
0

Share this post


Link to post
Share on other sites
Thanks for cross posting and reposting.

http://www.gamedev.net/topic/621717-intersection-of-two-3d-polyhedrons/page__pid__4930308#entry4930308
1

Share this post


Link to post
Share on other sites
your post was helpful, that's why I gave you points in reputation.
I just wanted to have a second advice, and because the previous topic was in general polyhedron, that's why I posted again.
Cause in the previous post I mentioned that they are convex only in an inside message
0

Share this post


Link to post
Share on other sites
That's not what concerns me. You should always give a link to what you have so far to prevent someone else wasting their time, giving the same, similar or less complete answers.
0

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
All I can say is that if you're going to be dealing with any sort of real complexity in your models, do [i]not[/i] go with the BSP approach.

PS: [url="https://www.google.com/search?source=ig&hl=en&rlz=&q=CSG+laidlaw&oq=CSG+laidlaw&aq=f&aqi=&aql=&gs_nf=1&gs_l=igoogle.3...23078.30761.0.31408.18.18.3.4.0.0.112.839.10j1.11.0."]click me[/url].
0

Share this post


Link to post
Share on other sites
Yeah, fortunately the BSP approach isn't necessary here. The thing that makes convex polyhedra unique is that they can be represented entirely as the intersection of a set of half spaces (constraints), and so can the intersection of an arbitrary set of convex polyhedron. To compute the intersection of two polyhedra, you just need to generate intersection of the union of the set of half-spaces.

The library approach would be to do the following: You start with the convex polyhedrons A and B, convert them to h-reps (set of half-spaces - in 3D, these will just be (oriented) plane equations), hrep(A) and hrep(B), then computer their union and convert back to the v-rep (set of vertices). So intersection(A,B) = vrep( union( hrep(A), hrep(B) ) ). Depending on what the library does, you may need to convert the resulting vertices into a trianguled hull (any convex hull implementation should do this for you).

[b]cdd[/b] converts between hreps and vreps ( [url="http://www.ifor.math.ethz.ch/~fukuda/cdd_home/index.html"]http://www.ifor.math...home/index.html[/url] ). Maybe the newer version also tesselates (I don't know - I used it last 11 years ago). Something like [b]QHull [/b]will generate the hull mesh [url="http://www.qhull.org/"]http://www.qhull.org/[/url].

The non-library/direct approach would be to just take polyhedron A, and iteratively refine it, by intersecting it with the half-spaces that make up polyhedron B. So, start with A, then for each triangle of B, compute the correctly oriented plane equation, and intersect A with the half space. The fundamental algorithmic primitive here is "polyhedron-halfspace intersection". This is actually, really easy to do - triangles of A completely on the outside of the half-space, are trivially discarded, triangles of A completely on the inside of the half-space are trivially kept. Triangles that cross the plane need to be clipped.

Triangle-plane clipping is easy, and implementations are widely available. The last piece of the puzzle is to take the new vertices, resulting from the clipping, and generate a "cap" polyhedron out of them. This is also easy, just project a copy of them onto a primary plane (use the largest component of the plane normal to decide which plane to prevent degenerate projections - i..e, if |x| is the largest, then project to the YZ plane), and sort them around their centroid by angle (use atan2).

Once you have the order of vertices, you can generate triangles from one vertex to all the others, and you're done.

Once you have gone through all triangles of B, you will be left with the intersection of A and B.
1

Share this post


Link to post
Share on other sites
Thanks Crowley for the advices in general!
I already implement your non-library/direct algorithm and works fine and it is fast!!!
Thanks
All the best
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