• 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
DuroSoft

Separating Axis Theorem in 3D between convex polygons

7 posts in this topic

My problem is as follows. I have two convex polygons (polygon A, polygon B) represented by two sets of 3D vertices. A and B can have any number of sides as long as they remain convex and have no holes or self-intersections (also, the vertices in a given list must be co-planar to each other to make a valid polygon). Polygon A and B can intersect with one another, but I can guarantee ahead of time that they will not have co-planar intersections (they won't be in the same plane and have an overlap region), so all intersections, if any, will be in the form of a line segment. I can also guarantee that A and B will never share an edge, if that helps. A and B can and frequently do have different numbers of sides, as well.

So, given only the two 3D vertex lists (which again represent two polygons in a 3D space), I need to use the separating axis theorem to find if there is a separating plane between the two polygons. If a separating plane does exist, I need to return the [b]equation[/b] for that plane (the plane equation that uses a normal to the plane is preferred). If there is no separating plane (if the polygons intersect), then I need to throw an error.

All the tutorials and articles I've read that deal with the separating axis theorem deal with either 2D objects in 2D space or 3D objects (e.g. polyhedra) in 3D space. I'm dealing with what I would call 2D polygons in a 3D space, so my unique situation has made it hard to follow these articles. I (conceptually) understand how this algorithm works in 2D, but in this situation, I am unsure which and how many edges need checking, and how exactly to go about the process as a whole. Additionally, I think usually the algorithm terminates the second it figures out whether or not there is a separating axis... I need to return the actual equation for the separating plane in the case that it exists, which I think is a little unusual. In many cases there are of course many possible separating planes... it doesn't matter for my purposes which one gets returned.

I would really appreciate some step-by-step advice for attacking this.

Thanks!!
0

Share this post


Link to post
Share on other sites
IIRC SAT works fine for convex polygones. If they are not coplanar the Minkowski sum will be a convex polyhedron and everything should work as usual. This means you have to test the two face normals and the edge cross products.
1

Share this post


Link to post
Share on other sites
[quote name='Dirk Gregorius' timestamp='1311018861' post='4836990']
IIRC SAT works fine for convex polygones. If they are not coplanar the Minkowski sum will be a convex polyhedron and everything should work as usual. This means you have to test the two face normals and the edge cross products.
[/quote]

Ok I think I understand what to do then. I'm assuming that by cross products you mean find the normals to the edges? In that case for those two polys I'd have to:

project onto the axis created by polygon A's face normal, testing for overlap
project onto the axis created by polygon B's face normal, testing for overlap
find the 7 edge normals (3 from polygon A, 4 from polygon B)
project onto the axis created by each of the 7 edge normals, testing for overlap

is this the right idea?

Also I'd be curious what the most efficient way to project the 3D coordinates in this scenario would be. After that step I'm pretty sure of what to do.

EDIT: after that point, I also need to figure out how to get the [b]equation[/b] for the separating plane, because I need that equation so I can do some point behind / in front of plane testing as the next step in this algorithm I'm working on.
0

Share this post


Link to post
Share on other sites
Here are some examples about SAT:
http://www.codercorner.com/blog/?p=24
http://www.codercorner.com/blog/?p=461
http://realtimecollisiondetection.net/pubs/GDC07_Ericson_Physics_Tutorial_SAT.ppt

Well if the separating axis is from a face you take the face plane. If the separating axis is from an edge pair you take the normal and one point on an edge to create a plane.


HTH,
-Dirk
0

Share this post


Link to post
Share on other sites
First off, since you're working in 3D, the separating axis is actually a separating plane.

I've been solving a similar problem very efficiently using the following method:

Intersect polygon A with the plane of polygon B, and intersect polygon B with the plane of polygon A. If each plane intersects the other's polygon, then you will have 2 collinear line segments representing the intersection regions. If not then the polygons do not intersect at all, so you can just choose the non-intersecting plane as your separating plane.
Now you need only check whether these line segments overlap to determine if the convex polygons are in intersection. This is similar to the SAT test, except you only have to look at a single axis. The axis in question is given by the cross product of the plane normals, or simply by constructing a vector from the plane-polygon intersection points (although I recommend using the cross product for stability reasons). You can determine the overlap by projecting the intersection points onto this vector.

You can use the line segment as the plane normal and choose a point between the two segments to construct the plane equaltion. If you need a separating axis instead then you'll need to choose an arbitrary vector on the plane. You can just rotate the plane normal (i.e. the line segment) 90 degrees around one of the unit axes, but make sure you don't choose an axis that the normal is already aligned with. The simplest thing to do is find the component of the normal with the smallest absolute value and rotate around the corresponding axis.

1

Share this post


Link to post
Share on other sites
[quote name='taz0010' timestamp='1311167111' post='4837944']
First off, since you're working in 3D, the separating axis is actually a separating plane.

I've been solving a similar problem very efficiently using the following method:

Intersect polygon A with the plane of polygon B, and intersect polygon B with the plane of polygon A. If each plane intersects the other's polygon, then you will have 2 collinear line segments representing the intersection regions. If not then the polygons do not intersect at all, so you can just choose the non-intersecting plane as your separating plane.
Now you need only check whether these line segments overlap to determine if the convex polygons are in intersection. This is similar to the SAT test, except you only have to look at a single axis. The axis in question is given by the cross product of the plane normals, or simply by constructing a vector from the plane-polygon intersection points (although I recommend using the cross product for stability reasons). You can determine the overlap by projecting the intersection points onto this vector.

You can use the line segment as the plane normal and choose a point between the two segments to construct the plane equaltion. If you need a separating axis instead then you'll need to choose an arbitrary vector on the plane. You can just rotate the plane normal (i.e. the line segment) 90 degrees around one of the unit axes, but make sure you don't choose an axis that the normal is already aligned with. The simplest thing to do is find the component of the normal with the smallest absolute value and rotate around the corresponding axis.
[/quote]


this is a rather ingenious method... is this documented anywhere or did you come up with this yourself?
0

Share this post


Link to post
Share on other sites
So if I got this right the process would be as follows:

1. loop through each line segment that makes up Polygon A, checking whether each segment intersects with Polygon B's plane. If no segments intersect, break early and return Polygon B's plane as the separating plane.
2. loop through each line segment that makes up Polygon B, checking whether each segment intersects with Polygon A's plane. If no segments intersect, break early and return Polygon A's plane as the separating plane.
4. If both 1 and 2 did find intersections, see if the two line segments overlap. If they do overlap, there is an intersection. Splitting one of the polygons down the line of intersection will resolve the intersection.
5. If the segments did not overlap, then the polygons do not intersect. To construct the separating plane, we use the cross product of the normals of the two planes as the normal, and for the location we select a point (let's say half way between) the two line segments (though any point within this region should be valid).


If I understand it correctly, this is really quite an elegant solution and I'm surprised I haven't read about it anywhere.
0

Share this post


Link to post
Share on other sites
[quote name='DuroSoft' timestamp='1311258475' post='4838459']
So if I got this right the process would be as follows:

1. loop through each line segment that makes up Polygon A, checking whether each segment intersects with Polygon B's plane. If no segments intersect, break early and return Polygon B's plane as the separating plane.
2. loop through each line segment that makes up Polygon B, checking whether each segment intersects with Polygon A's plane. If no segments intersect, break early and return Polygon A's plane as the separating plane.
4. If both 1 and 2 did find intersections, see if the two line segments overlap. If they do overlap, there is an intersection. Splitting one of the polygons down the line of intersection will resolve the intersection.
5. If the segments did not overlap, then the polygons do not intersect. To construct the separating plane, we use the cross product of the normals of the two planes as the normal, and for the location we select a point (let's say half way between) the two line segments (though any point within this region should be valid).


If I understand it correctly, this is really quite an elegant solution and I'm surprised I haven't read about it anywhere.
[/quote]

I don't know if the method is documented anywhere. I use it to determine whether I need to split up both convex and concave polygons to produce non-intersecting shapes. In the case of concave polygons, this method will sometimes incorrectly return intersection, in the same way that the SAT test fails on concave polygons. But resolving intersections of concave polygons is much slower, so I just split them anyway, which is an acceptable solution to my problem.


It's interesting that this method runs in O(n) but is only usable on polygons which lie on separate planes. I don't know of any O(n) methods that work on planar convex polygons.

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