1 #ifndef SimTK_SIMMATH_CONTACT_GEOMETRY_H_
2 #define SimTK_SIMMATH_CONTACT_GEOMETRY_H_
46 class ContactGeometryImpl;
47 class OBBTreeNodeImpl;
147 Vec3 findNearestPoint(
const Vec3& position,
bool& inside,
UnitVec3& normal)
const;
163 Vec3 projectDownhillToNearestPoint(
const Vec3& pointQ)
const;
229 bool trackSeparationFromLine(
const Vec3& pointOnLine,
231 const Vec3& startingGuessForClosestPoint,
232 Vec3& newClosestPointOnSurface,
233 Vec3& closestPointOnLine,
249 bool intersectsRay(
const Vec3& origin,
const UnitVec3& direction,
257 void getBoundingSphere(
Vec3& center,
Real& radius)
const;
262 bool isSmooth()
const;
280 void calcCurvature(
const Vec3& point,
Vec2& curvature,
293 const Function& getImplicitFunction()
const;
300 Real calcSurfaceValue(
const Vec3& point)
const;
312 UnitVec3 calcSurfaceUnitNormal(
const Vec3& point)
const;
319 Vec3 calcSurfaceGradient(
const Vec3& point)
const;
326 Mat33 calcSurfaceHessian(
const Vec3& point)
const;
356 Real calcGaussianCurvature(
const Vec3& gradient,
357 const Mat33& Hessian)
const;
363 return calcGaussianCurvature(calcSurfaceGradient(point),
364 calcSurfaceHessian(point));
375 Real calcSurfaceCurvatureInDirection(
const Vec3& point,
const UnitVec3& direction)
const;
379 bool isConvex()
const;
444 const Vec3& d2Pdu2,
const Vec3& d2Pdv2,
521 static void combineParaboloids(
const Rotation& R_SP1,
const Vec2& k1,
529 static void combineParaboloids(
const Rotation& R_SP1,
const Vec2& k1,
547 void initGeodesic(
const Vec3& xP,
const Vec3& xQ,
const Vec3& xSP,
594 void continueGeodesic(
const Vec3& xP,
const Vec3& xQ,
const Geodesic& prevGeod,
623 void makeStraightLineGeodesic(
const Vec3& xP,
const Vec3& xQ,
624 const UnitVec3& defaultDirectionIfNeeded,
638 void shootGeodesicInDirectionUntilLengthReached
655 void calcGeodesicReverseSensitivity
657 const Vec2& initSensitivity =
Vec2(0,1))
const;
671 void shootGeodesicInDirectionUntilPlaneHit(
const Vec3& xP,
const UnitVec3& tP,
678 void calcGeodesic(
const Vec3& xP,
const Vec3& xQ,
683 void calcGeodesicUsingOrthogonalMethod(
const Vec3& xP,
const Vec3& xQ,
688 void calcGeodesicUsingOrthogonalMethod(
const Vec3& xP,
const Vec3& xQ,
691 const Vec3 r_PQ = xQ - xP;
692 const Real lengthHint = r_PQ.
norm();
693 const UnitVec3 n = calcSurfaceUnitNormal(xP);
695 const Vec3 t_PQ = r_PQ - (~r_PQ*n)*n;
698 tLength != 0 ?
UnitVec3(t_PQ/tLength,
true)
700 calcGeodesicUsingOrthogonalMethod(xP, xQ,
Vec3(tPhint), lengthHint, geod);
728 void shootGeodesicInDirectionUntilLengthReachedAnalytical
745 void shootGeodesicInDirectionUntilPlaneHitAnalytical(
const Vec3& xP,
const UnitVec3& tP,
754 void calcGeodesicAnalytical(
const Vec3& xP,
const Vec3& xQ,
765 Vec2 calcSplitGeodErrorAnalytical(
const Vec3& P,
const Vec3& Q,
779 const Plane& getPlane()
const;
782 void setPlane(
const Plane& plane)
const;
787 const int getNumGeodesicsShot()
const;
794 bool isOwnerHandle()
const;
795 bool isEmptyHandle()
const;
798 const ContactGeometryImpl&
getImpl()
const {assert(impl);
return *impl;}
800 ContactGeometryImpl&
updImpl() {assert(impl);
return *impl; }
819 {
return geo.
getTypeId()==classTypeId(); }
822 { assert(isInstance(geo));
return static_cast<const HalfSpace&
>(geo); }
825 { assert(isInstance(geo));
return static_cast<HalfSpace&
>(geo); }
831 const Impl& getImpl()
const;
846 Real getRadius()
const;
847 void setRadius(
Real radius);
851 {
return geo.
getTypeId()==classTypeId(); }
854 { assert(isInstance(geo));
return static_cast<const Cylinder&
>(geo); }
857 { assert(isInstance(geo));
return static_cast<Cylinder&
>(geo); }
863 const Impl& getImpl()
const;
877 Real getRadius()
const;
878 void setRadius(
Real radius);
882 {
return geo.
getTypeId()==classTypeId(); }
885 { assert(isInstance(geo));
return static_cast<const Sphere&
>(geo); }
888 { assert(isInstance(geo));
return static_cast<Sphere&
>(geo); }
894 const Impl& getImpl()
const;
932 const Vec3& getRadii()
const;
938 void setRadii(
const Vec3& radii);
945 const Vec3& getCurvatures()
const;
968 Vec3 findPointWithThisUnitNormal(
const UnitVec3& n)
const;
978 Vec3 findPointInSameDirection(
const Vec3& Q)
const;
1009 void findParaboloidAtPointWithNormal(
const Vec3& Q,
const UnitVec3& n,
1014 {
return geo.
getTypeId()==classTypeId(); }
1017 { assert(isInstance(geo));
return static_cast<const Ellipsoid&
>(geo); }
1020 { assert(isInstance(geo));
return static_cast<Ellipsoid&
>(geo); }
1026 const Impl& getImpl()
const;
1059 const OBBTree& getOBBTree()
const;
1063 {
return geo.
getTypeId()==classTypeId(); }
1066 { assert(isInstance(geo));
return static_cast<const SmoothHeightMap&
>(geo); }
1069 { assert(isInstance(geo));
return static_cast<SmoothHeightMap&
>(geo); }
1075 const Impl& getImpl()
const;
1129 int getNumEdges()
const;
1131 int getNumFaces()
const;
1133 int getNumVertices()
const;
1137 const Vec3& getVertexPosition(
int index)
const;
1143 int getFaceEdge(
int face,
int edge)
const;
1148 int getFaceVertex(
int face,
int vertex)
const;
1153 int getEdgeFace(
int edge,
int face)
const;
1158 int getEdgeVertex(
int edge,
int vertex)
const;
1163 void findVertexEdges(
int vertex,
Array_<int>& edges)
const;
1166 const UnitVec3& getFaceNormal(
int face)
const;
1169 Real getFaceArea(
int face)
const;
1175 Vec3 findPoint(
int face,
const Vec2& uv)
const;
1180 Vec3 findCentroid(
int face)
const;
1185 UnitVec3 findNormalAtPoint(
int face,
const Vec2& uv)
const;
1196 Vec3 findNearestPoint(
const Vec3& position,
bool& inside,
UnitVec3& normal)
const;
1209 Vec3 findNearestPoint(
const Vec3& position,
bool& inside,
int& face,
Vec2& uv)
const;
1220 Vec3 findNearestPointToFace(
const Vec3& position,
int face,
Vec2& uv)
const;
1248 bool intersectsRay(
const Vec3& origin,
const UnitVec3& direction,
Real& distance,
int& face,
Vec2& uv)
const;
1259 {
return geo.
getTypeId()==classTypeId(); }
1262 { assert(isInstance(geo));
return static_cast<const TriangleMesh&
>(geo); }
1265 { assert(isInstance(geo));
return static_cast<TriangleMesh&
>(geo); }
1271 const Impl& getImpl()
const;
1291 bool isLeafNode()
const;
1304 int getNumTriangles()
const;
1307 const OBBTreeNodeImpl* impl;
1321 Real getTorusRadius()
const;
1322 void setTorusRadius(
Real radius);
1323 Real getTubeRadius()
const;
1324 void setTubeRadius(
Real radius);
1328 {
return geo.
getTypeId()==classTypeId(); }
1331 { assert(isInstance(geo));
return static_cast<const Torus&
>(geo); }
1334 { assert(isInstance(geo));
return static_cast<Torus&
>(geo); }
1340 const Impl& getImpl()
const;
1357 Plane() : m_normal(1,0,0), m_offset(0) { }
1359 : m_normal(normal), m_offset(offset) { }
1362 return ~m_normal*pt - m_offset;
1413 endpt[0] = q[0]; endpt[1] = q[1]; endpt[2] = q[2];
1417 shouldTerminate =
true;
1430 enabled = enabledFlag;
1438 mutable Plane plane;
1449 m_x(x), m_O(O), m_I(I), m_color(color) { }
1456 P[0] = m_x[0]; P[1] = m_x[1]; P[2] = m_x[2];
1457 Q[0] = m_x[3]; Q[1] = m_x[4]; Q[2] = m_x[5];
1466 .setLineThickness(2));
1469 .setLineThickness(2));
1477 const Vec3& m_color;
1489 m_plane(plane), m_color(color) { }
1502 .setTransform(
Transform(R_plane, R_plane*offset))
1504 .setOpacity(
Real(.2)));
1508 const Plane& m_plane;
1509 const Vec3& m_color;
1517 #endif // SimTK_SIMMATH_CONTACT_GEOMETRY_H_