Detecting convex areas from polygon soup

Started by
14 comments, last by funkeejeffounet 19 years, 8 months ago
This:

Quote:
I think if every polygon is on the front side of the plane of every other polygon, the group is convex.


equals this:

Quote:
Each polygon in the set is entirely contained in the half-space in front of every other polygon in the set.


Initially you didn't think this was the answer you were looking for, but you may not have understood what I meant.

Any planar polygon divides 3d space into two half-spaces, the space behind the plane of the polygon, and the space in front of the plane of the polygon.

A polygon can be tested against the plane of another polygon as follows. If all the verts of polygon A are on or in front of the plane of polygon B, polygon A is front of polygon B. If all the verts of polygon A are on or behind the plane of polygon B, polygon A is behind polygon B.

In a convex set of polygons, each polygon will be in front of the plane of every other polygon in the set (make sure to include an epsilon in your plane test). So a function might look something like:

bool IsConvex(Poly polys[], int numpolys)
{
for (int i = 0; i < numpolys; i++)
{
for (int j = 0; j < numpolys; j++)
{
if (i != j && polys.Test(polys[j]) == BEHIND)
return false;
}
}
return true;
}

That's just off the top of my head, so I can't swear by it. But I think something like this is the answer you're looking for.

[Edit]: sorry about the formatting.
Advertisement
Ok thks guys I understood what you said, and it seems to work for rooms(simple ones thought).
But something came to my mind. Imagine a sphere made of polygones, this object is convex as it can be drawn with no z sorting, but this time each polygone will be behind the planes of all other polygones?

Am I missing something...

Cheers, Jeff.
"Imagine a sphere made of polygones, this object is convex as it can be drawn with no z sorting, but this time each polygon will be behind the planes of all other polygons?"

Correct. For a room, each poly will be in front of every other poly. For a convex solid such a sphere, each poly will be behind every other poly.
Ok I get it now perfectly, thanks guys for helping me out and sorry jyk for misunderstanding you.

Cheers, Jeff.
Quote:Original post by funkeejeffounet
I don't think what you said is what I want, unless I didn't understood it.


No offence intended, but clearly you didn't understand it. The dimensionality of the problem is irrelevant in the definition of convexity above. Your polygon's are defined by vertices, which are just points in (in this scenario) 3-space. These points can be defined by vectors from your coordinate origin. If the set of all vectors defining the coordinates of the vertices of your object satisfy the above relationship then the volume they form in 3-space is convex (because the set of vectors is convex). You can apply this to any set in any number of dimensions. So, you could project all of these polygons into 2 dimensions and perform the same test to see if the projection is convex... or you could take a 10-dimensional set of points and perform the same convexity test.

If you've already found a solution your happy with, great... you may want to test this solution to see if it's computational cheaper, since it's essentially a set of linear operations and comparisons, which can be done with simple matrix algebra.

Cheers,

Timkin

When you first posted Timkin, I thought you talked of the vectors as being the one composing the polygones(one vertice of a poly minus another).
In fact you were talking of vectors defined by a vertice of a poly minus the origin.
Now I understand better.

But take the case, you have a room(cube) with a small doubled face rectangle in it for example. Your method will find this set of poly convex as it isn't, or am I missing something again :) ?

Cheers, Jeff.

This topic is closed to new replies.

Advertisement