Jump to content
  • Advertisement
Sign in to follow this  

point in polgyn test

This topic is 4817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I use the following algorithm to check if a point is in a triangle. The normal of the triangle is normalized. Should i normalize cp also in the following code?
bool CorrosionSim::pointInTriangle(const Vector3D& p, const Face& t)
{
  Vector3D p0=m_pObject->getMesh()->getVertex(t.getVertex(0)).getPosition(); 
  Vector3D p1=m_pObject->getMesh()->getVertex(t.getVertex(1)).getPosition();
  Vector3D p2=m_pObject->getMesh()->getVertex(t.getVertex(2)).getPosition();

  Vector3D n, cp;

  n=m_pObject->getMesh()->getFaceNormal(t.getNormal());
	
  Vector3D p0p=p0-p;
  Vector3D p1p=p1-p;

  cp.crossProduct(p0p, p1p);
  if(Vector3D::dotProduct(cp, n)<0.f)
	return false;

  Vector3D p2p=p2-p;
	
  cp.crossProduct(p1p, p2p);
  if(Vector3D::dotProduct(cp, n)<0.f)
	return false;
	
   cp.crossProduct(p2p, p0p);
   if(Vector3D::dotProduct(cp,n)<0.f)
	return false;

return true;
}

Share this post


Link to post
Share on other sites
Advertisement
It shouldn't matter whether or not cp is normalized. Is it not working? You might try changing < 0 to > 0 (if you haven't tried that already), just in case your cross products are pointing in the wrong direction. Other than that I'd have to look at the code more carefully, but can't now cause I'm at work - sorry!

Share this post


Link to post
Share on other sites
jyk is right, you don't need to normalize it.
The <0 is ok too, the function his based on the fact that if the point is outside at least one of the vectors you obtain with the cross product is opposite to the normal.

By the way, good idea, it's much faster than my PointInTriangle function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!