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 equation 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!!
Separating Axis Theorem in 3D between convex polygons
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.
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.
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 equation 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.
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
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
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.
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.
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.
this is a rather ingenious method... is this documented anywhere or did you come up with this yourself?
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement