View Full Version : Detecting if a point vector is inside a 3Dpolygon
claudiod 02-03-2009, 07:32 AM I could not find any math site or a C library to port to mel
how can I Detect if a point vector is inside a 3Dpolygon or not ?
|
|
scroll-lock
02-03-2009, 09:02 AM
search for barycentric coordinates ;)
Phlok
02-03-2009, 10:43 AM
If it's about libraries missing in MEL, you'd give Python a chance because all the Python modules available can be used in Maya.
Maybe you can find something useful there:
http://pyglet.org/
claudiod
02-03-2009, 08:28 PM
search for barycentric coordinates
thanks I wrote that function.but how can a polygon can be 3D triangulated (maya's own triangulate only works for poly faces not seperates whole object as pyramids)?
so my function may work
scroll-lock
02-04-2009, 12:03 PM
I don't think it's possible to see the triangles of a quad polygon without converting them to triangles. Or I don't know for such a solution. And if there is, what about non-planar quads ?
You can though cheat it by :
1) checking which four vertices make the quad polygon and evaluate the barycentric coordinates with vert 1, 2, 3 and then 3, 4, 1. If the point lies on one of them, then it will be on the quad polygon too ( if it's planar )
2) check which are the nearest three verts for the point and check if the point lies on the plane.
these are just thoughts though.. maybe there are other solutions too.
GennadiyKorol
02-04-2009, 04:19 PM
Why would you triangulate the mesh on your own? Not only would you need to triangulate the mesh again, you would need to make sure that the triangulation is consistent with Maya's one.
Instead use MFnMesh or MItMeshPolygon to obtain the triangulations of polygons.
Point lies on a polygon iff it lies on one of its triangles.
Point lies on a triangle if it lies on the plane of the triangle and is inside the triangle.
The most efficient way to test point inside triangle is using the abovementioned barycentric (normalized) coordinates.
It is easy to compute those using:
Normalized barycentric coord of point p for vertex v0 of the triangle is
Area of triangle (p, v1, v2) / Area of triangle t (v0, v1, v2)
Area of the triangle can be easily computed using the cross product for vectors.
If (a, b, c) be the barycentric coordinates of p in t. The point is inside of the triangle t iff 0 <= a + b + c < =1.
There are other ways but this one is probably the most cost-efficient.
trancor
02-04-2009, 07:58 PM
I'm probably not as savvy with the mathness as everyone else posting on this thread is, but this sounds like you'd need to check every triangle to each point you are checking to be inside of another object.
What about checking for the closest face to the vector in question, find the normal of that face (I forget the command for that, I'm caching now and can't open the mel reference) and use that normal in a dot product of the point and the normal. That will give you >0 for outside of the object and <0 for if the point is inside the object.
I mean, there is probably a lot of room for error, but on a situation to situation basis, but I'm just trying to think of other solutions here, correct me if I'm wrong.
CGTalk Moderation
02-04-2009, 07:58 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.