Archived

This topic is now archived and is closed to further replies.

Arch

Point position detection

Recommended Posts

Arch    122
Which is the faster metod to determine if a point is inside a polygon after I have verify than the point belong to the polygon''s plane ?? Thanks

Share this post


Link to post
Share on other sites
JuNC    236
''Faster'' is debatable, an easy way is to use the cross product test:


  
bool TestPtInFace(const std::vector<Point3>& pts,const Point3& pt,const Vector3& normal)
{
int ptCount = pts.size();

for(int i=0;i<ptCount;i++)
{
Vector3 edge = pts[(i+1)%ptCount] - pts[i];

if(Dot( Cross( edge, pt - pts[i] ),normal ) < 0)
return false;
}
return true;
}


Some say the barycentric method is better, others that some other way is better. At least the above code should work even if it''s not optimal.

Share this post


Link to post
Share on other sites
tok_junior    229
Would i be entirely wrong if i said that you should be able to dot the point with all three vertices of the triangle, and add the results together? If the result is 180 degrees it''s inside...
Something like that atleast ;P

--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

Share this post


Link to post
Share on other sites