# Physics Simulation Forum

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Support Mapping Function for Triangles with MPRPosted: Wed Mar 13, 2013 3:46 pm

Joined: Wed Mar 13, 2013 2:58 pm
Posts: 2
Hello Folks,

I am currently implementing a physics engine for a game project, modelling after XenoCollide by Gary Snethen. (Games Programming Gems 7)

I have a simple question with regards to support mapping function for triangles in 3D space.

Currently, this is what I have:

- Suppose the Triangle stores an array of 3 vertices.

Code:
void Triangle::GetSupportPoint(Vector3& point, const Vector3& normal)
{
f32 maxDist = FLT_MIN;
s32 maxIndex = -1;

for (s32 i = 0; i < 3; ++i)
{
f32 result = vertices_[i].Dot(normal);
if (result > maxDist)
{
maxIndex = i;
maxDist = result;
}
}
return vertices_[maxIndex];
}

I have tested this against a working box collider. (working on box-box etc.)

If I lay the triangle on the XZ plane, and have my camera looking down -Y at the triangle, it seems okay.
But in actual fact, if I were to look at it on the XY plane, there seem to be a "tetrahedron effect" on the triangle. It registers a false positive on the +Y side of the plane that slopes upwards until it converges above the centroid. Also, the contact normal were going +Y but sloped towards the outer vertex for some reason.

I believe my derivation is wrong.

I seek you professional people's advice if there's any way that I can do to "flatten" the collision area.

Thanks!
Jason

Last edited by jason.ngai on Sat Mar 16, 2013 11:32 am, edited 1 time in total.

Top

 Post subject: Re: Support Mapping Function for Triangles with MPRPosted: Thu Mar 14, 2013 3:38 pm

Joined: Wed Mar 13, 2013 2:58 pm
Posts: 2
Hello again,

**Edit 15th March 2013**
**Added a case for when the 2 centers are perfectly on-line to the origin ray.

I have found a solution that seems to work:

Code:
Vector3 Triangle::GetSupportPoint(const Vector3& normal) const
{
f32 maxDist = FLT_MIN;
s32 maxIndex = -1;

Sphere sphere(EPSILON); //Sphere collider

for (s32 i = 0; i < 3; ++i)
{
f32 result = vertices_[i].Dot(normal);
if (result > maxDist)
{
maxIndex = i;
maxDist = result;
}
}

// Slap an epsilon value against the normal of the triangle plane as "volume"
// So that MPR may terminate before it tries to construct the tetrahedron
Vector3 point = sphere.GetSupportPoint(normal);

// EDIT: Singularity when 2 centers are perfectly on-line to the normal from the origin
if (maxDist > EPSILON)
point += vertices_[maxIndex]; // Standard cases
else
point += (vertices_[0] + vertices_[1] + vertices_[2])/3; // Returns centroid instead

return point;
}

Basically, the main issues here is this:
Unlike rectangles, triangles does not come in a standard form, i.e., obtuse, acute, etc.
I attach a tiny value to the depth of the plane so that MPR could terminate earlier, allowing the triangle to behave as it should in 2D space.

The result I have achieved seems okay visually, I have yet to stress test it.

If anyone could verify or offer a better suggestion, please let us know!

Regards,
Jason

Top

 Post subject: Re: Support Mapping Function for Triangles with MPRPosted: Tue Apr 30, 2013 11:00 am

Joined: Fri Feb 24, 2012 10:45 am
Posts: 49
What is MPR? I use a triangle support function for GJK collision. You shouldn't need to do anything special for your triangle mapping function for GJK. There are degenerate cases (i.e. your triangle is a line or your tetrahedron is a triangle), but you can handle them pretty easily. Let me know if you've got it all figured out.

Mike

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

#### Who is online

Users browsing this forum: No registered users and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities