convex hull vs half-plane

User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

convex hull vs half-plane

Post by frca »

Hello,
how would you do this?
I want to collide convex hull vs half-plane and get the result as an intersecting point farthest from the line dividing the half-plane.
(I'm talking geometric-wise here, not physics-wise, so I need no btContactPoint generation, I need just one little btVector3 ;) ) Is this somehow possible in bullet?
Thank you.
Image
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: convex hull vs half-plane

Post by Erwin Coumans »

To get this point, you can use the 'getSupportingVertex' using the negative plane normal as direction. You just have to make sure to perform the operations in local space of the convex objects, and transform the resulting vertex back in worldspace.

This is implemented in the btConvexPlaneCollisionAlgorithm.cpp, see

Code: Select all

void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
{
    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
	btCollisionObject* planeObj = m_isSwapped? body0: body1;

	btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
	btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();

    bool hasCollision = false;
	const btVector3& planeNormal = planeShape->getPlaneNormal();
	const btScalar& planeConstant = planeShape->getPlaneConstant();
	
	btTransform convexWorldTransform = convexObj->getWorldTransform();
	btTransform convexInPlaneTrans;
	convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexWorldTransform;
	//now perturbe the convex-world transform
	convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot);
	btTransform planeInConvex;
	planeInConvex= convexWorldTransform.inverse() * planeObj->getWorldTransform();
	
	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);

	btVector3 vtxInPlane = convexInPlaneTrans(vtx);
	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);

	btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
	btVector3 vtxInPlaneWorld = planeObj->getWorldTransform() * vtxInPlaneProjected;

	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
	resultOut->setPersistentManifold(m_manifoldPtr);
	if (hasCollision)
	{
		/// report a contact. internally this will be kept persistent, and contact reduction is done
		btVector3 normalOnSurfaceB = planeObj->getWorldTransform().getBasis() * planeNormal;
		btVector3 pOnB = vtxInPlaneWorld;
		resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
	}
}
Thanks,
Erwin
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: convex hull vs half-plane

Post by frca »

What exactly does the localGetSupportingVertex function do? The documentation seems not to be very extensive on it.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: convex hull vs half-plane

Post by Erwin Coumans »

localGetSupportingVertex is an internal method, not meant to be directly used by most developers.

localGetSupportingVertex computes an extreme point for a convex object, given a certain direction. Read up on GJK for more information.
Thanks,
Erwin
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: convex hull vs half-plane

Post by frca »

So for a given convex hull, v as a parameter would give me A as in the picture? Did I get it right?
Image
Thanks
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: convex hull vs half-plane

Post by frca »

I made a little animation to better illustrate the problem:
Image