chrono::collision::utils Namespace Reference

Description

Collision detection utility functions.

Classes

class  ChConvexHullLibraryWrapper
 Wrapper for using and exporting the Bullet implementation of the convex hull library. More...
 

Functions

bool LineLineIntersect (const ChVector<> &p1, const ChVector<> &p2, const ChVector<> &p3, const ChVector<> &p4, ChVector<> *pa, ChVector<> *pb, double *mua, double *mub)
 Calculate the line segment PaPb that is the shortest route between two lines P1P2 and P3P4. More...
 
double PointLineDistance (const ChVector<> &p, const ChVector<> &dA, const ChVector<> &dB, double &mu, bool &is_insegment)
 Calculate distance between a point p and a line identified with segment dA,dB. More...
 
double PointTriangleDistance (const ChVector<> &B, const ChVector<> &A1, const ChVector<> &A2, const ChVector<> &A3, double &mu, double &mv, bool &is_into, ChVector<> &Bprojected)
 Calculate distance of a point from a triangle surface. More...
 
bool DegenerateTriangle (const ChVector<> &Dx, const ChVector<> &Dy)
 Check if the triangle defined by the two given vectors is degenerate.
 
bool DegenerateTriangle (const ChVector<> &v1, const ChVector<> &v2, const ChVector<> &v3)
 Check if the triangle defined by the three given vertices is degenerate.
 
btVector3 ProjectPointOnLine (const btVector3 &lP, const btVector3 &lD, const btVector3 &P)
 Project point onto line. More...
 
btScalar DistancePointToLine (const btVector3 &lP, const btVector3 &lD, const btVector3 &P)
 Calculate distance from point to line. More...
 
int SnapPointToBox (const btVector3 &hdims, btVector3 &loc)
 Snap the specified location to a point on a box with given half-dimensions. More...
 
bool PointInsideBox (const btVector3 &hdims, const btVector3 &loc)
 Check if given point is inside box (point expressed in box frame). More...
 
int FindClosestBoxFace (const btVector3 &hdims, const btVector3 &loc)
 Find the closest box face to the given point (expressed in box frame). More...
 
bool IntersectSegmentBox (const btVector3 &hdims, const btVector3 &c, const btVector3 &a, const btScalar hlen, const btScalar tol, btScalar &tMin, btScalar &tMax)
 
bool IntersectLinePlane (const btVector3 &lP, const btVector3 &lD, const btVector3 &pP, const btVector3 &pN, const btScalar tol, btScalar &t)
 Utility function to intersect a line with a plane Plane equation: pN.X = pN.pP Line equation: X = lP + t * lD Solution: t = pN. More...
 
bool IntersectSegmentCylinder (const btVector3 &sC, const btVector3 &sD, const btScalar sH, const btVector3 &cC, const btVector3 &cD, const btScalar cH, const btScalar cR, const btScalar tol, btScalar &tMin, btScalar &tMax)
 Utility function to intersect a segment with a cylinder. More...
 

Function Documentation

◆ DistancePointToLine()

ChApi btScalar chrono::collision::utils::DistancePointToLine ( const btVector3 &  lP,
const btVector3 &  lD,
const btVector3 &  P 
)

Calculate distance from point to line.

Parameters
lPpoint on line
lDline direction (unit vector)
Ppoint

◆ FindClosestBoxFace()

ChApi int chrono::collision::utils::FindClosestBoxFace ( const btVector3 &  hdims,
const btVector3 &  loc 
)

Find the closest box face to the given point (expressed in box frame).

Returns +1, +2, +3 (for a "positive" face in x, y, z, respectively) or -1, -2, -3 (for a "negative" face).

Parameters
hdimsbox half-dimensions
locpoint

◆ IntersectLinePlane()

ChApi bool chrono::collision::utils::IntersectLinePlane ( const btVector3 &  lP,
const btVector3 &  lD,
const btVector3 &  pP,
const btVector3 &  pN,
const btScalar  tol,
btScalar &  t 
)

Utility function to intersect a line with a plane Plane equation: pN.X = pN.pP Line equation: X = lP + t * lD Solution: t = pN.

(pP-lP) / pN.lD

Parameters
lPpoint on line
lDline direction (unit vector)
pPpoint on plane
pNplane normal (unit vector)
toltolerance for orthogonality test
tline parameter of intersection point

◆ IntersectSegmentBox()

ChApi bool chrono::collision::utils::IntersectSegmentBox ( const btVector3 &  hdims,
const btVector3 &  c,
const btVector3 &  a,
const btScalar  hlen,
const btScalar  tol,
btScalar &  tMin,
btScalar &  tMax 
)
Parameters
hdimsbox half-dimensions
csegment center point
asegment direction (unit vector)
hlensegment half-length
toltolerance for parallelism test
tMinsegment parameter of first intersection point
tMaxsegment parameter of second intersection point

◆ IntersectSegmentCylinder()

ChApi bool chrono::collision::utils::IntersectSegmentCylinder ( const btVector3 &  sC,
const btVector3 &  sD,
const btScalar  sH,
const btVector3 &  cC,
const btVector3 &  cD,
const btScalar  cH,
const btScalar  cR,
const btScalar  tol,
btScalar &  tMin,
btScalar &  tMax 
)

Utility function to intersect a segment with a cylinder.

Segment assumed to be parameterized as sP = sC + t * sD, with -sH <= t <= sH. Cylinder given by its center cC, axis direction cD, halh-lengh cH, and radius cR. Assume |sD| = |cD| = 1. (1) Find tMin and tMax where the segment supporting line intersects cylindrical surface by finding points on segment at a distance cR from the cylinder axis line. (2) Clamp result to cylinder end-caps. (3) Clamp result to segment length.

Parameters
sCsegment center point
sDsegment direction (unit vector)
sHsegment half-length
cCcylinder axis center
cDcylinder axis direction (unit vector)
cHcylinder axis half-length (cylinder halh-height)
cRcylinder radius
toltolerance for parallelism test
tMinsegment parameter of first intersection point
tMaxsegment parameter of second intersection point

◆ LineLineIntersect()

ChApi bool chrono::collision::utils::LineLineIntersect ( const ChVector<> &  p1,
const ChVector<> &  p2,
const ChVector<> &  p3,
const ChVector<> &  p4,
ChVector<> *  pa,
ChVector<> *  pb,
double *  mua,
double *  mub 
)

Calculate the line segment PaPb that is the shortest route between two lines P1P2 and P3P4.

Calculate also the values of mua and mub where Pa = P1 + mua (P2 - P1) Pb = P3 + mub (P4 - P3) Return false if no solution exists.

◆ PointInsideBox()

ChApi bool chrono::collision::utils::PointInsideBox ( const btVector3 &  hdims,
const btVector3 &  loc 
)

Check if given point is inside box (point expressed in box frame).

Parameters
hdimsbox half-dimensions
locpoint

◆ PointLineDistance()

ChApi double chrono::collision::utils::PointLineDistance ( const ChVector<> &  p,
const ChVector<> &  dA,
const ChVector<> &  dB,
double &  mu,
bool &  is_insegment 
)

Calculate distance between a point p and a line identified with segment dA,dB.

Returns distance. Also, the mu value reference tells if the nearest projection of point on line falls into segment (for mu 0...1)

◆ PointTriangleDistance()

ChApi double chrono::collision::utils::PointTriangleDistance ( const ChVector<> &  B,
const ChVector<> &  A1,
const ChVector<> &  A2,
const ChVector<> &  A3,
double &  mu,
double &  mv,
bool &  is_into,
ChVector<> &  Bprojected 
)

Calculate distance of a point from a triangle surface.

Also computes if projection is inside the triangle. If is_into = true, Bprojected is also computed. Returns distance (positive if 'out' side, out is where points A1 A2 A3 can be read in clockwise fashion)

◆ ProjectPointOnLine()

ChApi btVector3 chrono::collision::utils::ProjectPointOnLine ( const btVector3 &  lP,
const btVector3 &  lD,
const btVector3 &  P 
)

Project point onto line.

Parameters
lPpoint on line
lDline direction (unit vector)
Ppoint

◆ SnapPointToBox()

ChApi int chrono::collision::utils::SnapPointToBox ( const btVector3 &  hdims,
btVector3 &  loc 
)

Snap the specified location to a point on a box with given half-dimensions.

The in/out location is assumed to be specified in the frame of the box (which is therefore assumed to be an AABB centered at the origin). The return code indicates the box axes that caused snapping:

  • first bit (least significant) corresponds to x-axis
  • second bit corresponds to y-axis
  • third bit corresponds to z-axis

Therefore: code = 0 indicates an interior point code = 1 or code = 2 or code = 4 indicates snapping to a face code = 3 or code = 5 or code = 6 indicates snapping to an edge code = 7 indicates snapping to a corner

Parameters
hdimsbox half-dimensions
locpoint (in/out)