9#include "sfh/math/math.h"
16typedef Eigen::Matrix<double,3,1> cvec3;
17typedef Eigen::Matrix<int,3,1> cvec3i;
18typedef Eigen::Quaternion<double> cquat;
21inline double PointDistance3D(
const cvec3 &PA,
const cvec3 &PB)
23 return sqrt((PA(0)-PB(0))*(PA(0)-PB(0))+(PA(1)-PB(1))*(PA(1)-PB(1))+(PA(2)-PB(2))*(PA(2)-PB(2)));
28inline double PointPlaneDis(
const cvec3 &V0,
const cvec3 &P0,
const cvec3 &PN)
31 return VP.dot(PN.normalized());
36int rayTri(
const cvec3 &V1,
const cvec3 &V2,
const cvec3 &V3,
const cvec3 &O,
const cvec3 &D,
double &out);
40int SegmentPlane(
const cvec3 &S0,
const cvec3 &S1,
const cvec3 &P0,
const cvec3 &PN, cvec3 &SPI);
49 minloc(0) = minloc(1) = minloc(2) = std::numeric_limits<double>::max();
50 maxloc(0) = maxloc(1) = maxloc(2) = -std::numeric_limits<double>::max();
53 AABB(
const AABB &aabb) {
60 void add(
const cvec3 &v) {
61 if (v(0) < minloc(0)) minloc(0) = v(0);
62 if (v(1) < minloc(1)) minloc(1) = v(1);
63 if (v(2) < minloc(2)) minloc(2) = v(2);
64 if (v(0) > maxloc(0)) maxloc(0) = v(0);
65 if (v(1) > maxloc(1)) maxloc(1) = v(1);
66 if (v(2) > maxloc(2)) maxloc(2) = v(2);
70 minloc(0) = minloc(1) = minloc(2) = std::numeric_limits<double>::max();
71 maxloc(0) = maxloc(1) = maxloc(2) = -std::numeric_limits<double>::max();
74 int overlap(
const AABB &aabb)
76 if(maxloc(0) < aabb.minloc(0) || minloc(0) > aabb.maxloc(0))
return 0;
77 if(maxloc(1) < aabb.minloc(1) || minloc(1) > aabb.maxloc(1))
return 0;
78 if(maxloc(2) < aabb.minloc(2) || minloc(2) > aabb.maxloc(2))
return 0;
83 double overlapvolume(
const AABB &aabb, cvec3 &minol, cvec3 &maxol)
85 minol(0) = std::max(minloc(0),aabb.minloc(0));
86 maxol(0) = std::min(maxloc(0),aabb.maxloc(0));
87 minol(1) = std::max(minloc(1),aabb.minloc(1));
88 maxol(1) = std::min(maxloc(1),aabb.maxloc(1));
89 minol(2) = std::max(minloc(2),aabb.minloc(2));
90 maxol(2) = std::min(maxloc(2),aabb.maxloc(2));
92 double volume = std::abs((maxol(0)-minol(0))*(maxol(1)-minol(1))*(maxol(2)-minol(2)));
97 int border(
const AABB &aabb,
double &tol)
99 if(PointDistance3D(minloc,aabb.minloc)>tol)
return 0;
100 if(PointDistance3D(maxloc,aabb.maxloc)>tol)
return 0;
125 ISignalPort* InObjPos;
138 virtual ~ContactObject();
140 void InitialSetup(ISimObjectCreator* creator);
141 void UpdateObjectState(
const double T,
const double*
const X);
143 int PointPenetration(
const cvec3 &O,
const double &r,
double &oPen, cvec3 &oInt);
144 void PointContactForce(
const cvec3 &cPos,
const cvec3 &cVel,
const double &cPen,
const cvec3 &cInt, cvec3 &cFor, cvec3 &cMon);
146 double PointDistance(
const cvec3 &O,
const double &r);