7 #include "imstkSphereToSphereCD.h" 8 #include "imstkCollisionData.h" 9 #include "imstkCollisionUtils.h" 10 #include "imstkSphere.h" 14 SphereToSphereCD::SphereToSphereCD() : CollisionDetectionAlgorithm()
16 setRequiredInputType<Sphere>(0);
17 setRequiredInputType<Sphere>(1);
22 std::shared_ptr<Geometry> geomA,
23 std::shared_ptr<Geometry> geomB,
24 std::vector<CollisionElement>& elementsA,
25 std::vector<CollisionElement>& elementsB)
27 std::shared_ptr<Sphere> sphereA = std::dynamic_pointer_cast<
Sphere>(geomA);
28 std::shared_ptr<Sphere> sphereB = std::dynamic_pointer_cast<
Sphere>(geomB);
32 const double rA = sphereA->getRadius();
33 const Vec3d sphereBPos = sphereB->getPosition();
34 const double rB = sphereB->getRadius();
36 Vec3d sphereAContactPt, sphereBContactPt;
37 Vec3d sphereAContactNormal, sphereBContactNormal;
39 if (CollisionUtils::testSphereToSphere(
40 sphereAPos, rA, sphereBPos, rB,
41 sphereAContactPt, sphereAContactNormal,
42 sphereBContactPt, sphereBContactNormal,
46 elemA.dir = sphereAContactNormal;
47 elemA.pt = sphereAContactPt;
48 elemA.penetrationDepth = depth;
51 elemB.dir = sphereBContactNormal;
52 elemB.pt = sphereBContactPt;
53 elemB.penetrationDepth = depth;
55 elementsA.push_back(elemA);
56 elementsB.push_back(elemB);
Vec3d getPosition(DataType type=DataType::PostTransform)
Get the local or global position (post transformed)
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.