7 #include "imstkEdgeEdgeCCDState.h" 11 EdgeEdgeCCDState::EdgeEdgeCCDState(
const Vec3d& i0,
const Vec3d& i1,
const Vec3d& j0,
const Vec3d& j1)
12 : xi(i0), xi1(i1), xj(j0), xj1(j1),
13 ei(xi1 - xi), ej(xj1 - xj), w0(xj - xi),
14 w(shortestDistanceVector())
36 VertexPair(
const Vec3d& diff,
double si,
double sj) : m_diff(diff), m_si(si), m_sj(sj)
39 bool operator<(
const VertexPair& A)
const 41 return(this->m_diff.norm() < A.m_diff.norm());
45 VertexPair p1(xj - xi, 0, 0);
46 VertexPair p2(xj1 - xi, 1, 0);
47 VertexPair p3(xj - xi1, 0, 1);
48 VertexPair p4(xj1 - xi1, 1, 1);
49 auto result = std::min<VertexPair>({ p1, p2, p3, p4 });
68 Vec3d p2 = (xj1 - xi);
69 Vec3d p3 = (xj - xi1);
70 Vec3d p4 = (xj1 - xi1);
71 return std::min<Vec3d>({ p1, p2, p3, p4 }, [](
const Vec3d& a,
const Vec3d& b) {
return (a.norm() < b.norm()); });
77 relativeTimeOfImpact = 0.0;
78 const double tol = 0.01;
79 const bool externalIntersection = (curr.
si() < 0 - tol || curr.
si() > 1 + tol || curr.
sj() < 0 - tol || curr.
sj() > 1 + tol);
81 Vec3d curr_wbar = curr.
w;
82 if (externalIntersection)
87 if (curr_wbar.norm() < prev.thickness() + prev.m_epsilon)
89 relativeTimeOfImpact = 1.0;
90 return externalIntersection ? 2 : 1;
93 const bool crossedEachOther = (prev.
w.dot(curr.
w) < 0);
94 if (crossedEachOther && !externalIntersection)
96 double m = std::copysign(1.0, curr.
w.dot(prev.
w));
97 double denom = prev.
w.norm() - m * curr.
w.norm();
99 if (denom > prev.m_epsilon)
101 relativeTimeOfImpact = prev.
w.norm() / (prev.
w.norm() - m * curr.
w.norm());
110 EdgeEdgeCCDState::computeSi()
const 112 double ac_bb = denom();
113 if (abs(ac_bb) < m_epsilon)
122 return -1.0 * (b() * e() - c() * d()) / ac_bb;
126 EdgeEdgeCCDState::computeSj()
const 128 double ac_bb = denom();
129 if (abs(ac_bb) < m_epsilon)
145 return -1.0 * (a() * e() - b() * d()) / ac_bb;
149 EdgeEdgeCCDState::shortestDistanceVector()
const 151 auto n = ei.cross(ej).normalized();
Vec3d computeWBar2() const
const Vec3d w
Shortest distance vector between the infinite lines defined by the two segments.
static int testCollision(const EdgeEdgeCCDState &prev, EdgeEdgeCCDState &curr, double &relativeTimeOfImpact)
Performs a collision test based on two given timesteps that store the state of two lines each...
const double sj() const
Parameterized position of closest point on segment xj–xj1 to segment xi–xi1.
const double si() const
Parameterized position of closest point on segment xi–xi1 to segment xj–xj1.