7 #include "imstkSphereToCylinderCD.h" 8 #include "imstkCollisionData.h" 9 #include "imstkCollisionUtils.h" 10 #include "imstkCylinder.h" 11 #include "imstkSphere.h" 15 SphereToCylinderCD::SphereToCylinderCD()
17 setRequiredInputType<Sphere>(0);
18 setRequiredInputType<Cylinder>(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<Sphere> sphere = std::dynamic_pointer_cast<
Sphere>(geomA);
29 std::shared_ptr<Cylinder> cylinder = std::dynamic_pointer_cast<
Cylinder>(geomB);
33 const double rSphere = sphere->getRadius();
35 const Vec3d cylinderPos = cylinder->getPosition();
36 const Vec3d cylinderAxis = cylinder->getOrientation().toRotationMatrix().col(1);
37 const double rCylinder = cylinder->getRadius();
38 const double cylLength = cylinder->getLength();
40 Vec3d sphereContactPt, cylinderContactPt;
41 Vec3d sphereContactNormal, cylinderContactNormal;
43 if (CollisionUtils::testSphereToCylinder(
45 cylinderPos, cylinderAxis, rCylinder, cylLength,
46 sphereContactPt, sphereContactNormal,
47 cylinderContactPt, cylinderContactNormal,
51 elemA.dir = sphereContactNormal;
52 elemA.pt = sphereContactPt;
53 elemA.penetrationDepth = depth;
56 elemB.dir = cylinderContactNormal;
57 elemB.pt = cylinderContactPt;
58 elemB.penetrationDepth = depth;
60 elementsA.push_back(elemA);
61 elementsB.push_back(elemB);
Cylinder geometry, default configuration is at origin with length running up the y axes...
Vec3d getPosition(DataType type=DataType::PostTransform)
Get the local or global position (post transformed)
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.
Represents a sphere via its position & radius.
Direclty gives a point-direction contact as its collision data.