How to check whether a point is inside a mesh or not?

Post Reply
sarbartha88
Posts: 3
Joined: Mon Jun 15, 2015 5:24 pm

How to check whether a point is inside a mesh or not?

Post by sarbartha88 »

I have a triangulated Human mesh ... I am trying to check whether a oint is inside a the mesh or not. My code if following:

Code: Select all

btTriangleMesh* trimesh = new btTriangleMesh();
	delete(human); 
	human = NULL;
	for (int i = 0; i < av->vertI; i++)
	{
		btVector3 a(btScalar(av->vertices[av->faces[i][0][0]][0]), btScalar(av->vertices[av->faces[i][0][0]][1]), btScalar(av->vertices[av->faces[i][0][0]][2]));
		btVector3 b(btScalar(av->vertices[av->faces[i][1][0]][0]), btScalar(av->vertices[av->faces[i][1][0]][1]), btScalar(av->vertices[av->faces[i][1][0]][2]));
		btVector3 c(btScalar(av->vertices[av->faces[i][2][0]][0]), btScalar(av->vertices[av->faces[i][2][0]][1]), btScalar(av->vertices[av->faces[i][2][0]][2]));

		trimesh->addTriangle(a,b,c, true);

	}	
	human =  new btConvexTriangleMeshShape(trimesh);
	
	CString s;
	btVector3 cx(btScalar(0.0), btScalar(-2.0), btScalar(0.0));
	if (human->isInside(btVector3(0.000000 ,- 1.455000, 1.209952), btScalar(0.1)))
	{
		OutputDebugString(L"True\n");
	}
	else
		OutputDebugString(L"False\n");
Its always giving false .. but the mesh got created properly ... I am getting its center and other functions are working ... only isInside is giving false.
donggas90
Posts: 17
Joined: Tue May 19, 2015 10:01 am

Re: How to check whether a point is inside a mesh or not?

Post by donggas90 »

First, my answer is not the Bullet specific.

We can make a plane from three points what are from a triangle by cross products.
Thus a trimesh can assume as a group of planes.

On the other hand, we can determine position of a point from a plane, whether above or under by dot product.

Finally, we can deduce that, if a point is 'under' all the planes what are from a trimesh, the point is inside the trimesh.
Post Reply