Skip to main content
GameDev.net gamedev.net
🔒 Locked

Point position detection

Started by Arch Mar 8, 2003 at 3:30 AM 2 replies 200+ views
Original Post
Arch
Arch
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
JuNC
JuNC
''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.
tok_junior
tok_junior
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.
Arch
Arch
Anybody know the HAINES (1991) metod ?

Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.