**0**

# Minkowski addition and convex hulls.

###
#1
Crossbones+ - Reputation: **3219**

Posted 17 December 2012 - 01:08 AM

I know their's alot of papers with convex hulls represented by vertice's. but i am representing mine with a series of planes, this is fine for most intersection code, but i can't find anything for using the minkowski addition with such a representation.

does anyone know of any papers on the subject, at worse i can re-write how i represent the hulls to be vertice based, but i'd rather work with planes, since that's what it generally comes down to.

###
#3
Crossbones+ - Reputation: **3219**

Posted 17 December 2012 - 04:13 AM

with vertices, i'd have to translate each vertices by the matrix, and potentially recalculate the planes(probably simpler than also translating them by the matrix), they defiantly arn't as intuitive as working with vertices, but their defiantly faster for doing general purpose calculations on a convex hull.

so, at the moment, i thought i had come up with an algorithm for doing the sum of two objects, but it seems i'm missing something crucial, if both shapes are the same size, but just rotated, the algorithm can handle it, just not if the object is two diffrent sizes.

this is my current code:

//Note: both hulls are already made to be around zero, so no tranlation is required. QWConvexHull *MiniskySum(QWConvexHull *A, QWConvexHull *B){ unsigned int Len = A->GetPlaneCount()+B->GetPlaneCount(); if(!Len) return 0x0; QWVector4 *R = new QWVector4[Len]; Len=0; //Add the first object as the starting shape. for(unsigned int i=0;i<A->GetPlaneCount();i++) R[Len++] = A->GetTranslatedPlane(i); //go through each point of A: for(unsigned int i=0;i<A->GetPlaneCount();i++){ QWVector4 AP = A->GetTranslatedPlane(i); QWVector3 AT = QWVector3(AP.x*AP.w, AP.y*AP.w, AP.z*AP.w); //calculate the point of the plane for the convex hull. for(unsigned int d=0;d<B->GetPlaneCount();d++){ QWVector4 BP = B->GetTranslatedPlane(d); QWVector3 BT = QWVector3(BP.x*BP.w, BP.y*BP.w, BP.z*BP.w); //calculate the point for B's plane. BT = AT+BT; /Combine the two! unsigned char RF=0; for(unsigned int x=0;x<Len;x++){ //discover if this point is inside the existing convex hull. if(QWConvexHull::PlanePointDistance(R[x], BT)>QWEPSILON){ RF=1; break; } } //If it's inside, we ignore this plane. if(!RF) continue; //Calculate the resulting point's plane relative to the origin. //since BT is not in the unit sphere, but does exist on the correct plane, we translate the resulting plane's D component to be at the correct distance. QWVector4 Z = QWVector4(BP.x, BP.y, BP.z, (BP.x*BT.x+BP.y*BT.y+BP.z*BT.z)); R[Len++] = Z; //currently, we brute force to figure out if their are any plane points that are inside our finished hull. for(unsigned int x=0;x<Len;x++){ QWVector3 P = QWVector3(R[x].x*R[x].w, R[x].y*R[x].w, R[x].z*R[x].w); for(unsigned int y=0;y<Len;y++){ if(QWConvexHull::PlanePointDistance(R[y], P)>=QWEPSILON){ //We've discovered y is inside of x, so we get rid of y. R[y--] = R[--Len]; break; } } } } } //Now just build the actual hull. QWConvexHull *H = new QWConvexHull(A->GetCenter()); for(unsigned int i=0;i<Len;i++) H->PushPlane(R[i]); //QWConvexHull *Hull delete[] R; return H; }

###
#4
Members - Reputation: **340**

Posted 17 December 2012 - 06:08 AM

Besides, you're not saving that much space by using the plane equation. More precisely, for zero genus, closed, triangulated surface with 'n' vertices, you'll use '8n-16' fp units to store the planes, on the other hand you'll use '3n' fp units and '6n-12' integer units to store the vertices and indices.

Also, what general purpose calculations are better be done on plane equations than on points? I ask this because all implementations that I've done so far faired far better with verts/indcs representation. For instance you want to do Minkowski sums, they're quite easy when it's just points, but working with normals makes things more complicated.

###
#5
Crossbones+ - Reputation: **3219**

Posted 17 December 2012 - 06:49 AM

Applying transformations directly to normals will work correctly only with orthogonal transformations. For general transforms you'll have to use the cofactor matrix.

Besides, you're not saving that much space by using the plane equation. More precisely, for zero genus, closed, triangulated surface with 'n' vertices, you'll use '8n-16' fp units to store the planes, on the other hand you'll use '3n' fp units and '6n-12' integer units to store the vertices and indices.

Also, what general purpose calculations are better be done on plane equations than on points? I ask this because all implementations that I've done so far faired far better with verts/indcs representation. For instance you want to do Minkowski sums, they're quite easy when it's just points, but working with normals makes things more complicated.

think about what information needs to be represented from that triangle, if you want to test if a point is inside your convex hull, then you need to test that it's inside all the planes of each triangle, if you want to test ray intersection with your triangle, first you have to get the point's intersection point with the plane that the triangle resides on, then you have to test that the point is inside the triangle.

for example, i just implemented a function that can get the surface point of my convex hull from any given direction, it operates in O(n) time where n is the number of planes:

//where R is some large number. QWVector3 QWConvexHull::GetSurfacePoint(QWVector3 Direction, float R){ QWVector3 E = Direction*R; for(unsigned int i=m_PlaneCount;i<m_PlaneCount*2;i++){ QWVector4 P = m_PlaneList[i]; float Dot = P.x*E.x+P.y*E.y+P.z*E.z; if(QWFCmp(Dot, 0.0f)) continue; float D = P.w/Dot; if(D<1.0f && D>0.0f) E*=D; } return m_Center+E; }

if we just use planes to start with, you can encode with less space, and you don't have to generate the normals from the geometry, since your providing those normals directly.

anyways, for the moment i've decided to use minkowski diffrence for collision detection, although if anyone has more information on this subject, please point me to it, as i'd like to use minkowski sum for doing sweep checks.

###
#6
Members - Reputation: **340**

Posted 17 December 2012 - 07:41 AM

think about what information needs to be represented from that triangle, if you want to test if a point is inside your convex hull, then you need to test that it's inside all the planes of each triangle, if you want to test ray intersection with your triangle, first you have to get the point's intersection point with the plane that the triangle resides on, then you have to test that the point is inside the triangle.

Testing whether a point is inside a convex mesh takes O(log(n)) time. Why test it against all triangles?

Same thing goes for intersecting a ray with a convex mesh. Testing it against all triangles is suboptimal (can be done in O(log(n)) time).

**Edited by max343, 17 December 2012 - 07:42 AM.**

###
#7
Crossbones+ - Reputation: **3219**

Posted 17 December 2012 - 07:54 AM

here's an idea, link me to relevant information, you say it can be done in O(log(n)), then tell me how, instead of just making wild claims.

think about what information needs to be represented from that triangle, if you want to test if a point is inside your convex hull, then you need to test that it's inside all the planes of each triangle, if you want to test ray intersection with your triangle, first you have to get the point's intersection point with the plane that the triangle resides on, then you have to test that the point is inside the triangle.

Testing whether a point is inside a convex mesh takes O(log(n)) time. Why test it against all triangles?

Same thing goes for intersecting a ray with a convex mesh. Testing it against all triangles is suboptimal (can be done in O(log(n)) time).

###
#9
Crossbones+ - Reputation: **3219**

Posted 17 December 2012 - 08:32 AM

Amazing... Wild claims? Instead of being rude (and down-voting) you can just read some textbook on computational geometry.

Lookup what is Dobkin-Kirkpatrick hierarchy.

uhh buddy, maybe you should actually check my rep events before making such claims, idk who down voted you,

as for the post on hand, all you had to do was throw out that name in the last post, rather than pretty much insulting the way i was doing, and telling me their's a better way to do something, without actually telling me how it's done. all i was asking is for the algorithm that you were talking about.

**Edited by slicer4ever, 17 December 2012 - 08:36 AM.**

###
#10
Members - Reputation: **340**

Posted 17 December 2012 - 08:58 AM

But still, if you see something that is not familiar to you, instead of saying that it's a wild claim, you can just ask on how it's done. I didn't elaborate on it simply because it's a relatively basic topic in computational geometry, so I wasn't sure what's exactly the problem.

Now that I see what the problem is, I can give you the full answer. Using plane equations for meshes is suboptimal for this types of queries, because you want to exploit the convexity of your mesh. Multiple plane equations don't contain that information explicitly. On the other hand using verts/indcs is useful because you can construct the Dobkin-Kirkpatrick hierarchy (during pre-processing, takes linear time) and traverse only the most relevant parts of your convex mesh which results in a logarithmic time algorithm.

Implementation details can be found in almost any textbook that mentions this hierarchy.

###
#11
Crossbones+ - Reputation: **3219**

Posted 17 December 2012 - 09:09 AM

Now that I see what the problem is, I can give you the full answer. Using plane equations for meshes is suboptimal for this types of queries, because you want to exploit the convexity of your mesh. Multiple plane equations don't contain that information explicitly. On the other hand using verts/indcs is useful because you can construct the Dobkin-Kirkpatrick hierarchy (during pre-processing, takes linear time) and traverse only the most relevant parts of your convex mesh which results in a logarithmic time algorithm.

Implementation details can be found in almost any textbook that mentions this hierarchy.

thank you, i'm currently reading over a pdf about Dobkin-Kirkpatric right now to get a better grasp on the subject. I've never had any formal training on computational geometry, so it's not uncommon for me to run into an new approach to a problem that essentially shines a bright light at things i've been trying to do, but didn't know proper terms for them, so usually it ends up getting done haphazardly.

I am coming to the realization that storing only planes provides only enough information for simple query's into the object, I just discovered that the implementation i created for doing minkowski diffrence has faults in the fact that drawing a straight line between two objects can cause missed collisions.