iMSTK
Interactive Medical Simulation Toolkit
imstkEdgeEdgeCCDState.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkMath.h"
10 
11 namespace imstk
12 {
18 {
19 public:
20 
21  /*
22  _o (xi1)
23  _-*
24  _-*
25 (xi) o* (segment i)
26  ^
27  |
28  (w0)|
29  |
30  (xj)o----------o (xj1)
31  (segment j)
32  */
33 
36  const Vec3d& xi, & xi1, & xj, & xj1;
37 
39  const Vec3d ei;
40  const Vec3d ej;
41 
42  const Vec3d w0;
43 
45  const Vec3d w;
46 
47  EdgeEdgeCCDState(const Vec3d& i0, const Vec3d& i1, const Vec3d& j0, const Vec3d& j1);
48 
50  const double si() const
51  {
52  return m_si;
53  }
54 
56  const double sj() const
57  {
58  return m_sj;
59  }
60 
62  const Vec3d& pi() const
63  {
64  return m_pi;
65  }
66 
68  const Vec3d& pj() const
69  {
70  return m_pj;
71  }
72 
75  Vec3d computeWBar();
76 
79  Vec3d computeWBar2() const;
80 
82  Vec3d computePi() const
83  {
84  return xi + ei * si();
85  }
86 
88  Vec3d computePj() const
89  {
90  return xj + ej * sj();
91  }
92 
93  void setThickness(double thickness)
94  {
95  m_thickness = thickness;
96  }
97 
98  double thickness() const
99  {
100  return m_thickness;
101  }
102 
103  void setTolerance(double eps)
104  {
105  m_epsilon = eps;
106  }
107 
115  static int testCollision(const EdgeEdgeCCDState& prev, EdgeEdgeCCDState& curr, double& relativeTimeOfImpact);
116 
117 private:
118 
119  double m_si;
120  double m_sj;
121 
122  Vec3d m_pi;
123  Vec3d m_pj;
124 
125  double m_epsilon = 1e-10;
126 
127  // Thickness of colliding LineMeshes.
128  double m_thickness = 0.0016; // 0.0016
129 
131  double a() const
132  {
133  return ei.dot(ei);
134  }
135 
137  double b() const
138  {
139  return ei.dot(ej);
140  }
141 
143  double c() const
144  {
145  return ej.dot(ej);
146  }
147 
149  double d() const
150  {
151  return ei.dot(w0);
152  }
153 
155  double e() const
156  {
157  return ej.dot(w0);
158  }
159 
161  double denom() const
162  {
163  return a() * c() - b() * b();
164  }
165 
167  double computeSi() const;
168 
170  double computeSj() const;
171 
173  Vec3d shortestDistanceVector() const;
174 };
175 } // namespace imstk
const Vec3d ej
vector defining segment j (xj1 - xj)
const Vec3d & pj() const
Pj is the closest point on segment xj–xj1 to segment xi–xi1.
const Vec3d & pi() const
Pi is the closest point on segment xi–xi1 to segment xj–xj1.
Compound Geometry.
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 Vec3d ei
Vectors that represent the edges / line-segments.
Vec3d computePi() const
Pi and Pj are closest points on segments xi–xi1 and xj–xj1 respectively.
const double sj() const
Parameterized position of closest point on segment xj–xj1 to segment xi–xi1.
Vec3d computePj() const
Pi and Pj are closest points on segments xi–xi1 and xj–xj1 respectively.
const double si() const
Parameterized position of closest point on segment xi–xi1 to segment xj–xj1.
const Vec3d w0
vector from first point on segement i to first point on segment j (xj - xi)