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,
250 Real& distance,
UnitVec3& normal)
const;
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
639 (
const Vec3& xP,
const UnitVec3& tP,
const Real& terminatingLength,
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,
684 const Vec3& tPhint, Real lengthHint,
Geodesic& geod)
const;
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;
696 const Real tLength = t_PQ.
norm();
698 tLength != 0 ?
UnitVec3(t_PQ/tLength,
true)
700 calcGeodesicUsingOrthogonalMethod(xP, xQ,
Vec3(tPhint), lengthHint, geod);
728 void shootGeodesicInDirectionUntilLengthReachedAnalytical
729 (
const Vec3& xP,
const UnitVec3& tP,
const Real& terminatingLength,
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;
876 explicit Sphere(Real radius);
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;
1234 bool intersectsRay(
const Vec3& origin,
const UnitVec3& direction, Real& distance,
UnitVec3& normal)
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;
1320 Torus(Real torusRadius, Real tubeRadius);
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_
This class will create a smooth surface that approximates a two-argument function F(X...
Definition: BicubicSurface.h:158
ScheduledEventReporter is a subclass of EventReporter for events that occur at a particular time that...
Definition: EventReporter.h:72
UnitVec< P, 1 > perp() const
Return a new unit vector perpendicular to this one but otherwise arbitrary.
Definition: UnitVec.h:182
Plane(const Vec3 &normal, const Real &offset)
Definition: ContactGeometry.h:1358
This defines a rectangular solid centered at the origin and aligned with the local frame axes...
Definition: DecorativeGeometry.h:334
SimTK_DEFINE_UNIQUE_INDEX_TYPE(AssemblyConditionIndex)
A simple plane class.
Definition: ContactGeometry.h:1355
UnitVec< Real, 1 > UnitVec3
Definition: UnitVec.h:41
This class generates decoration for contact points and straight line path segments.
Definition: ContactGeometry.h:1446
const void setEnabled(bool enabledFlag)
Definition: ContactGeometry.h:1429
Plane()
Definition: ContactGeometry.h:1357
GeodHitPlaneEvent(const Plane &aplane)
Definition: ContactGeometry.h:1388
const bool isEnabled()
Definition: ContactGeometry.h:1433
Definition: CoordinateAxis.h:196
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition: Stage.h:50
PathDecorator(const Vector &x, const Vec3 &O, const Vec3 &I, const Vec3 &color)
Definition: ContactGeometry.h:1448
This class stores a geodesic curve after it has been determined.
Definition: Geodesic.h:51
This file defines the BicubicSurface class, and the BicubicFunction class that uses it to create a tw...
This class represents a rectangular box with arbitrary position and orientation.
Definition: OrientedBoundingBox.h:42
void handleEvent(State &state, Real accuracy, bool &shouldTerminate) const
This method is invoked to handle the event.
Definition: ContactGeometry.h:1405
virtual void generateDecorations(const State &state, Array_< DecorativeGeometry > &geometry)
This will be called every time a new State is about to be visualized.
Definition: ContactGeometry.h:1491
PlaneDecorator(const Plane &plane, const Vec3 &color)
Definition: ContactGeometry.h:1488
Vec< 2 > Vec2
Definition: SmallMatrix.h:103
This is the handle class for the hidden State implementation.
Definition: State.h:264
const Complex I
We only need one complex constant, i = sqrt(-1). For the rest just multiply the real constant by i...
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
A DecorationGenerator is used to define geometry that may change over the course of a simulation...
Definition: DecorationGenerator.h:45
This class generates decoration for a plane.
Definition: ContactGeometry.h:1486
This class stores options for calculating geodesics.
Definition: Geodesic.h:311
const Plane & getPlane() const
Definition: ContactGeometry.h:1425
Real getDistance(const Vec3 &pt) const
Definition: ContactGeometry.h:1361
This class provides a description of a mesh made of polygonal faces (not limited to triangles)...
Definition: PolygonalMesh.h:71
This is the header file that every Simmath compilation unit should include first. ...
This is the client-side interface to an implementation-independent representation of "Decorations" su...
Definition: DecorativeGeometry.h:86
This defines a sphere centered at the origin.
Definition: DecorativeGeometry.h:301
This Array_ helper class is the base class for ArrayView_ which is the base class for Array_; here we...
Definition: Array.h:48
virtual void generateDecorations(const State &state, Array_< DecorativeGeometry > &geometry)
This will be called every time a new State is about to be visualized.
Definition: ContactGeometry.h:1451
TODO.
Definition: OBBTree.h:100
TriggeredEventHandler is a subclass of EventHandler for events that occur when some condition is sati...
Definition: EventHandler.h:109
Real getOffset() const
Definition: ContactGeometry.h:1369
Vec3 getNormal() const
Definition: ContactGeometry.h:1365
const Vector & getQ(SubsystemIndex) const
Per-subsystem access to the global shared variables.
CNT< ScalarNormSq >::TSqrt norm() const
Definition: Vec.h:555
Vec< 3 > Vec3
Definition: SmallMatrix.h:104
void setPlane(const Plane &aplane) const
Definition: ContactGeometry.h:1421
This class represents a small matrix whose size is known at compile time, containing elements of any ...
Definition: Mat.h:51
A line between two points.
Definition: DecorativeGeometry.h:254
Real getValue(const State &state) const
Get the value of the event trigger function for a State.
Definition: ContactGeometry.h:1394
void push_back(const T &value)
This method increases the size of the Array by one element at the end and initializes that element by...
Definition: Array.h:2329
This file defines the Geodesic class.
A event handler to terminate integration when geodesic hits the plane.
Definition: ContactGeometry.h:1383
GeodHitPlaneEvent()
Definition: ContactGeometry.h:1385
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
Transform_< Real > Transform
Definition: Transform.h:44
Rotation_ & setRotationFromOneAxis(const UnitVec3P &uvec, const CoordinateAxis axis)
Calculate R_AB by knowing one of B's unit vector expressed in A.
const Vec3 Black
RGB=( 0, 0, 0)