7 #include "imstkUnidirectionalPlaneToSphereCD.h" 8 #include "imstkCollisionData.h" 9 #include "imstkCollisionUtils.h" 10 #include "imstkPlane.h" 11 #include "imstkSphere.h" 15 UnidirectionalPlaneToSphereCD::UnidirectionalPlaneToSphereCD()
17 setRequiredInputType<Plane>(0);
18 setRequiredInputType<Sphere>(1);
23 std::shared_ptr<Geometry> geomA,
24 std::shared_ptr<Geometry> geomB,
25 std::vector<CollisionElement>& elementsA,
26 std::vector<CollisionElement>& elementsB)
28 std::shared_ptr<Plane> plane = std::dynamic_pointer_cast<
Plane>(geomA);
29 std::shared_ptr<Sphere> sphere = std::dynamic_pointer_cast<
Sphere>(geomB);
33 const double r = sphere->getRadius();
34 const Vec3d planePos = plane->getPosition();
35 const Vec3d n = plane->getNormal();
37 Vec3d planeContactPt, sphereContactPt;
38 Vec3d planeContactNormal, sphereContactNormal;
40 if (CollisionUtils::testPlaneToSphere(
43 planeContactPt, planeContactNormal,
44 sphereContactPt, sphereContactNormal,
48 elemA.dir = planeContactNormal;
49 elemA.pt = planeContactPt;
50 elemA.penetrationDepth = depth;
53 elemB.dir = sphereContactNormal;
54 elemB.pt = sphereContactPt;
55 elemB.penetrationDepth = depth;
57 elementsA.push_back(elemA);
58 elementsB.push_back(elemB);
Vec3d getPosition(DataType type=DataType::PostTransform)
Get the local or global position (post transformed)
Represents and infinite plane, width can be used for visual purposes.
Represents a sphere via its position & radius.
void computeCollisionDataAB(std::shared_ptr< Geometry > geomA, std::shared_ptr< Geometry > geomB, std::vector< CollisionElement > &elementsA, std::vector< CollisionElement > &elementsB) override
Compute collision data for AB simultaneously.
Direclty gives a point-direction contact as its collision data.