FCL  0.6.0
Flexible Collision Library
halfspace-inl.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
38 #ifndef FCL_NARROWPHASE_DETAIL_HALFSPACE_INL_H
39 #define FCL_NARROWPHASE_DETAIL_HALFSPACE_INL_H
40 
41 #include "fcl/narrowphase/detail/primitive_shape_algorithm/halfspace.h"
42 
43 namespace fcl
44 {
45 
46 namespace detail
47 {
48 
49 //==============================================================================
50 extern template
51 bool sphereHalfspaceIntersect(
52  const Sphere<double>& s1, const Transform3<double>& tf1,
53  const Halfspace<double>& s2, const Transform3<double>& tf2,
54  std::vector<ContactPoint<double>>* contacts);
55 
56 //==============================================================================
57 extern template
58 bool ellipsoidHalfspaceIntersect(
59  const Ellipsoid<double>& s1, const Transform3<double>& tf1,
60  const Halfspace<double>& s2, const Transform3<double>& tf2,
61  std::vector<ContactPoint<double>>* contacts);
62 
63 //==============================================================================
64 extern template
65 bool boxHalfspaceIntersect(
66  const Box<double>& s1, const Transform3<double>& tf1,
67  const Halfspace<double>& s2, const Transform3<double>& tf2);
68 
69 //==============================================================================
70 extern template
71 bool boxHalfspaceIntersect(
72  const Box<double>& s1, const Transform3<double>& tf1,
73  const Halfspace<double>& s2, const Transform3<double>& tf2,
74  std::vector<ContactPoint<double>>* contacts);
75 
76 //==============================================================================
77 extern template
78 bool capsuleHalfspaceIntersect(
79  const Capsule<double>& s1, const Transform3<double>& tf1,
80  const Halfspace<double>& s2, const Transform3<double>& tf2,
81  std::vector<ContactPoint<double>>* contacts);
82 
83 //==============================================================================
84 extern template
85 bool cylinderHalfspaceIntersect(
86  const Cylinder<double>& s1, const Transform3<double>& tf1,
87  const Halfspace<double>& s2, const Transform3<double>& tf2,
88  std::vector<ContactPoint<double>>* contacts);
89 
90 //==============================================================================
91 extern template
92 bool coneHalfspaceIntersect(
93  const Cone<double>& s1, const Transform3<double>& tf1,
94  const Halfspace<double>& s2, const Transform3<double>& tf2,
95  std::vector<ContactPoint<double>>* contacts);
96 
97 //==============================================================================
98 extern template
99 bool convexHalfspaceIntersect(
100  const Convex<double>& s1, const Transform3<double>& tf1,
101  const Halfspace<double>& s2, const Transform3<double>& tf2,
102  Vector3<double>* contact_points, double* penetration_depth, Vector3<double>* normal);
103 
104 //==============================================================================
105 extern template
106 bool halfspaceTriangleIntersect(
107  const Halfspace<double>& s1, const Transform3<double>& tf1,
108  const Vector3<double>& P1, const Vector3<double>& P2, const Vector3<double>& P3, const Transform3<double>& tf2,
109  Vector3<double>* contact_points, double* penetration_depth, Vector3<double>* normal);
110 
111 //==============================================================================
112 extern template
113 bool planeHalfspaceIntersect(
114  const Plane<double>& s1, const Transform3<double>& tf1,
115  const Halfspace<double>& s2, const Transform3<double>& tf2,
116  Plane<double>& pl,
117  Vector3<double>& p, Vector3<double>& d,
118  double& penetration_depth,
119  int& ret);
120 
121 //==============================================================================
122 extern template
123 bool halfspacePlaneIntersect(
124  const Halfspace<double>& s1, const Transform3<double>& tf1,
125  const Plane<double>& s2, const Transform3<double>& tf2,
126  Plane<double>& pl, Vector3<double>& p, Vector3<double>& d,
127  double& penetration_depth,
128  int& ret);
129 
130 //==============================================================================
131 extern template
132 bool halfspaceIntersect(
133  const Halfspace<double>& s1, const Transform3<double>& tf1,
134  const Halfspace<double>& s2, const Transform3<double>& tf2,
135  Vector3<double>& p, Vector3<double>& d,
136  Halfspace<double>& s,
137  double& penetration_depth,
138  int& ret);
139 
140 //==============================================================================
141 template <typename S>
142 S halfspaceIntersectTolerance()
143 {
144  return 0;
145 }
146 
147 //==============================================================================
148 template <typename S>
149 bool sphereHalfspaceIntersect(const Sphere<S>& s1, const Transform3<S>& tf1,
150  const Halfspace<S>& s2, const Transform3<S>& tf2,
151  std::vector<ContactPoint<S>>* contacts)
152 {
153  const Halfspace<S> new_s2 = transform(s2, tf2);
154  const Vector3<S>& center = tf1.translation();
155  const S depth = s1.radius - new_s2.signedDistance(center);
156 
157  if (depth >= 0)
158  {
159  if (contacts)
160  {
161  const Vector3<S> normal = -new_s2.n; // pointing from s1 to s2
162  const Vector3<S> point = center - new_s2.n * s1.radius + new_s2.n * (depth * 0.5);
163  const S penetration_depth = depth;
164 
165  contacts->emplace_back(normal, point, penetration_depth);
166  }
167 
168  return true;
169  }
170  else
171  {
172  return false;
173  }
174 }
175 
176 //==============================================================================
177 template <typename S>
178 bool ellipsoidHalfspaceIntersect(const Ellipsoid<S>& s1, const Transform3<S>& tf1,
179  const Halfspace<S>& s2, const Transform3<S>& tf2,
180  std::vector<ContactPoint<S>>* contacts)
181 {
182  // We first compute a single contact in the ellipsoid coordinates, tf1, then
183  // will transform it to the world frame. So we use a new halfspace that is
184  // expressed in the ellipsoid coordinates.
185  const Halfspace<S>& new_s2 = transform(s2, tf1.inverse(Eigen::Isometry) * tf2);
186 
187  // Compute distance between the ellipsoid's center and a contact plane, whose
188  // normal is equal to the halfspace's normal.
189  const Vector3<S> normal2(std::pow(new_s2.n[0], 2), std::pow(new_s2.n[1], 2), std::pow(new_s2.n[2], 2));
190  const Vector3<S> radii2(std::pow(s1.radii[0], 2), std::pow(s1.radii[1], 2), std::pow(s1.radii[2], 2));
191  const S center_to_contact_plane = std::sqrt(normal2.dot(radii2));
192 
193  // Depth is the distance between the contact plane and the halfspace.
194  const S depth = center_to_contact_plane + new_s2.d;
195 
196  if (depth >= 0)
197  {
198  if (contacts)
199  {
200  // Transform the results to the world coordinates.
201  const Vector3<S> normal = tf1.linear() * -new_s2.n; // pointing from s1 to s2
202  const Vector3<S> support_vector = (1.0/center_to_contact_plane) * Vector3<S>(radii2[0]*new_s2.n[0], radii2[1]*new_s2.n[1], radii2[2]*new_s2.n[2]);
203  const Vector3<S> point_in_halfspace_coords = support_vector * (0.5 * depth / new_s2.n.dot(support_vector) - 1.0);
204  const Vector3<S> point = tf1 * point_in_halfspace_coords; // roughly speaking, a middle point of the intersecting volume
205  const S penetration_depth = depth;
206 
207  contacts->emplace_back(normal, point, penetration_depth);
208  }
209 
210  return true;
211  }
212  else
213  {
214  return false;
215  }
216 }
217 
218 //==============================================================================
219 template <typename S>
220 bool boxHalfspaceIntersect(const Box<S>& s1, const Transform3<S>& tf1,
221  const Halfspace<S>& s2, const Transform3<S>& tf2)
222 {
223  Halfspace<S> new_s2 = transform(s2, tf2);
224 
225  const Matrix3<S>& R = tf1.linear();
226  const Vector3<S>& T = tf1.translation();
227 
228  Vector3<S> Q = R.transpose() * new_s2.n;
229  Vector3<S> A(Q[0] * s1.side[0], Q[1] * s1.side[1], Q[2] * s1.side[2]);
230  Vector3<S> B = A.cwiseAbs();
231 
232  S depth = 0.5 * (B[0] + B[1] + B[2]) - new_s2.signedDistance(T);
233  return (depth >= 0);
234 }
235 
236 //==============================================================================
237 template <typename S>
238 bool boxHalfspaceIntersect(const Box<S>& s1, const Transform3<S>& tf1,
239  const Halfspace<S>& s2, const Transform3<S>& tf2,
240  std::vector<ContactPoint<S>>* contacts)
241 {
242  if(!contacts)
243  {
244  return boxHalfspaceIntersect(s1, tf1, s2, tf2);
245  }
246  else
247  {
248  const Halfspace<S> new_s2 = transform(s2, tf2);
249 
250  const Matrix3<S>& R = tf1.linear();
251  const Vector3<S>& T = tf1.translation();
252 
253  Vector3<S> Q = R.transpose() * new_s2.n;
254  Vector3<S> A(Q[0] * s1.side[0], Q[1] * s1.side[1], Q[2] * s1.side[2]);
255  Vector3<S> B = A.cwiseAbs();
256 
257  S depth = 0.5 * (B[0] + B[1] + B[2]) - new_s2.signedDistance(T);
258  if(depth < 0) return false;
259 
260  Vector3<S> axis[3];
261  axis[0] = R.col(0);
262  axis[1] = R.col(1);
263  axis[2] = R.col(2);
264 
266  Vector3<S> p(T);
267  int sign = 0;
268 
269  if(std::abs(Q[0] - 1) < halfspaceIntersectTolerance<S>() || std::abs(Q[0] + 1) < halfspaceIntersectTolerance<S>())
270  {
271  sign = (A[0] > 0) ? -1 : 1;
272  p += axis[0] * (0.5 * s1.side[0] * sign);
273  }
274  else if(std::abs(Q[1] - 1) < halfspaceIntersectTolerance<S>() || std::abs(Q[1] + 1) < halfspaceIntersectTolerance<S>())
275  {
276  sign = (A[1] > 0) ? -1 : 1;
277  p += axis[1] * (0.5 * s1.side[1] * sign);
278  }
279  else if(std::abs(Q[2] - 1) < halfspaceIntersectTolerance<S>() || std::abs(Q[2] + 1) < halfspaceIntersectTolerance<S>())
280  {
281  sign = (A[2] > 0) ? -1 : 1;
282  p += axis[2] * (0.5 * s1.side[2] * sign);
283  }
284  else
285  {
286  for(std::size_t i = 0; i < 3; ++i)
287  {
288  sign = (A[i] > 0) ? -1 : 1;
289  p += axis[i] * (0.5 * s1.side[i] * sign);
290  }
291  }
292 
294  if (contacts)
295  {
296  const Vector3<S> normal = -new_s2.n;
297  const Vector3<S> point = p + new_s2.n * (depth * 0.5);
298  const S penetration_depth = depth;
299 
300  contacts->emplace_back(normal, point, penetration_depth);
301  }
302 
303  return true;
304  }
305 }
306 
307 //==============================================================================
308 template <typename S>
309 bool capsuleHalfspaceIntersect(const Capsule<S>& s1, const Transform3<S>& tf1,
310  const Halfspace<S>& s2, const Transform3<S>& tf2,
311  std::vector<ContactPoint<S>>* contacts)
312 {
313  Halfspace<S> new_s2 = transform(s2, tf2);
314 
315  const Matrix3<S>& R = tf1.linear();
316  const Vector3<S>& T = tf1.translation();
317 
318  Vector3<S> dir_z = R.col(2);
319 
320  S cosa = dir_z.dot(new_s2.n);
321  if(std::abs(cosa) < halfspaceIntersectTolerance<S>())
322  {
323  S signed_dist = new_s2.signedDistance(T);
324  S depth = s1.radius - signed_dist;
325  if(depth < 0) return false;
326 
327  if (contacts)
328  {
329  const Vector3<S> normal = -new_s2.n;
330  const Vector3<S> point = T + new_s2.n * (0.5 * depth - s1.radius);
331  const S penetration_depth = depth;
332 
333  contacts->emplace_back(normal, point, penetration_depth);
334  }
335 
336  return true;
337  }
338  else
339  {
340  int sign = (cosa > 0) ? -1 : 1;
341  Vector3<S> p = T + dir_z * (s1.lz * 0.5 * sign);
342 
343  S signed_dist = new_s2.signedDistance(p);
344  S depth = s1.radius - signed_dist;
345  if(depth < 0) return false;
346 
347  if (contacts)
348  {
349  const Vector3<S> normal = -new_s2.n;
350  const Vector3<S> point = p - new_s2.n * s1.radius + new_s2.n * (0.5 * depth); // deepest point
351  const S penetration_depth = depth;
352 
353  contacts->emplace_back(normal, point, penetration_depth);
354  }
355 
356  return true;
357  }
358 }
359 
360 //==============================================================================
361 template <typename S>
362 bool cylinderHalfspaceIntersect(const Cylinder<S>& s1, const Transform3<S>& tf1,
363  const Halfspace<S>& s2, const Transform3<S>& tf2,
364  std::vector<ContactPoint<S>>* contacts)
365 {
366  Halfspace<S> new_s2 = transform(s2, tf2);
367 
368  const Matrix3<S>& R = tf1.linear();
369  const Vector3<S>& T = tf1.translation();
370 
371  Vector3<S> dir_z = R.col(2);
372  S cosa = dir_z.dot(new_s2.n);
373 
374  if(cosa < halfspaceIntersectTolerance<S>())
375  {
376  S signed_dist = new_s2.signedDistance(T);
377  S depth = s1.radius - signed_dist;
378  if(depth < 0) return false;
379 
380  if (contacts)
381  {
382  const Vector3<S> normal = -new_s2.n;
383  const Vector3<S> point = T + new_s2.n * (0.5 * depth - s1.radius);
384  const S penetration_depth = depth;
385 
386  contacts->emplace_back(normal, point, penetration_depth);
387  }
388 
389  return true;
390  }
391  else
392  {
393  Vector3<S> C = dir_z * cosa - new_s2.n;
394  if(std::abs(cosa + 1) < halfspaceIntersectTolerance<S>() || std::abs(cosa - 1) < halfspaceIntersectTolerance<S>())
395  C = Vector3<S>(0, 0, 0);
396  else
397  {
398  S s = C.norm();
399  s = s1.radius / s;
400  C *= s;
401  }
402 
403  int sign = (cosa > 0) ? -1 : 1;
404  // deepest point
405  Vector3<S> p = T + dir_z * (s1.lz * 0.5 * sign) + C;
406  S depth = -new_s2.signedDistance(p);
407  if(depth < 0) return false;
408  else
409  {
410  if (contacts)
411  {
412  const Vector3<S> normal = -new_s2.n;
413  const Vector3<S> point = p + new_s2.n * (0.5 * depth);
414  const S penetration_depth = depth;
415 
416  contacts->emplace_back(normal, point, penetration_depth);
417  }
418 
419  return true;
420  }
421  }
422 }
423 
424 //==============================================================================
425 template <typename S>
426 bool coneHalfspaceIntersect(const Cone<S>& s1, const Transform3<S>& tf1,
427  const Halfspace<S>& s2, const Transform3<S>& tf2,
428  std::vector<ContactPoint<S>>* contacts)
429 {
430  Halfspace<S> new_s2 = transform(s2, tf2);
431 
432  const Matrix3<S>& R = tf1.linear();
433  const Vector3<S>& T = tf1.translation();
434 
435  Vector3<S> dir_z = R.col(2);
436  S cosa = dir_z.dot(new_s2.n);
437 
438  if(cosa < halfspaceIntersectTolerance<S>())
439  {
440  S signed_dist = new_s2.signedDistance(T);
441  S depth = s1.radius - signed_dist;
442  if(depth < 0) return false;
443  else
444  {
445  if (contacts)
446  {
447  const Vector3<S> normal = -new_s2.n;
448  const Vector3<S> point = T - dir_z * (s1.lz * 0.5) + new_s2.n * (0.5 * depth - s1.radius);
449  const S penetration_depth = depth;
450 
451  contacts->emplace_back(normal, point, penetration_depth);
452  }
453 
454  return true;
455  }
456  }
457  else
458  {
459  Vector3<S> C = dir_z * cosa - new_s2.n;
460  if(std::abs(cosa + 1) < halfspaceIntersectTolerance<S>() || std::abs(cosa - 1) < halfspaceIntersectTolerance<S>())
461  C = Vector3<S>(0, 0, 0);
462  else
463  {
464  S s = C.norm();
465  s = s1.radius / s;
466  C *= s;
467  }
468 
469  Vector3<S> p1 = T + dir_z * (0.5 * s1.lz);
470  Vector3<S> p2 = T - dir_z * (0.5 * s1.lz) + C;
471 
472  S d1 = new_s2.signedDistance(p1);
473  S d2 = new_s2.signedDistance(p2);
474 
475  if(d1 > 0 && d2 > 0) return false;
476  else
477  {
478  if (contacts)
479  {
480  const S penetration_depth = -std::min(d1, d2);
481  const Vector3<S> normal = -new_s2.n;
482  const Vector3<S> point = ((d1 < d2) ? p1 : p2) + new_s2.n * (0.5 * penetration_depth);
483 
484  contacts->emplace_back(normal, point, penetration_depth);
485  }
486 
487  return true;
488  }
489  }
490 }
491 
492 //==============================================================================
493 template <typename S>
494 bool convexHalfspaceIntersect(const Convex<S>& s1, const Transform3<S>& tf1,
495  const Halfspace<S>& s2, const Transform3<S>& tf2,
496  Vector3<S>* contact_points, S* penetration_depth, Vector3<S>* normal)
497 {
498  Halfspace<S> new_s2 = transform(s2, tf2);
499 
500  Vector3<S> v;
501  S depth = std::numeric_limits<S>::max();
502 
503  for(int i = 0; i < s1.num_points; ++i)
504  {
505  Vector3<S> p = tf1 * s1.points[i];
506 
507  S d = new_s2.signedDistance(p);
508  if(d < depth)
509  {
510  depth = d;
511  v = p;
512  }
513  }
514 
515  if(depth <= 0)
516  {
517  if(contact_points) *contact_points = v - new_s2.n * (0.5 * depth);
518  if(penetration_depth) *penetration_depth = depth;
519  if(normal) *normal = -new_s2.n;
520  return true;
521  }
522  else
523  return false;
524 }
525 
526 //==============================================================================
527 template <typename S>
528 bool halfspaceTriangleIntersect(const Halfspace<S>& s1, const Transform3<S>& tf1,
529  const Vector3<S>& P1, const Vector3<S>& P2, const Vector3<S>& P3, const Transform3<S>& tf2,
530  Vector3<S>* contact_points, S* penetration_depth, Vector3<S>* normal)
531 {
532  Halfspace<S> new_s1 = transform(s1, tf1);
533 
534  Vector3<S> v = tf2 * P1;
535  S depth = new_s1.signedDistance(v);
536 
537  Vector3<S> p = tf2 * P2;
538  S d = new_s1.signedDistance(p);
539  if(d < depth)
540  {
541  depth = d;
542  v = p;
543  }
544 
545  p = tf2 * P3;
546  d = new_s1.signedDistance(p);
547  if(d < depth)
548  {
549  depth = d;
550  v = p;
551  }
552 
553  if(depth <= 0)
554  {
555  if(penetration_depth) *penetration_depth = -depth;
556  if(normal) *normal = new_s1.n;
557  if(contact_points) *contact_points = v - new_s1.n * (0.5 * depth);
558  return true;
559  }
560  else
561  return false;
562 }
563 
564 //==============================================================================
565 template <typename S>
566 bool planeHalfspaceIntersect(const Plane<S>& s1, const Transform3<S>& tf1,
567  const Halfspace<S>& s2, const Transform3<S>& tf2,
568  Plane<S>& pl,
569  Vector3<S>& p, Vector3<S>& d,
570  S& penetration_depth,
571  int& ret)
572 {
573  Plane<S> new_s1 = transform(s1, tf1);
574  Halfspace<S> new_s2 = transform(s2, tf2);
575 
576  ret = 0;
577 
578  Vector3<S> dir = (new_s1.n).cross(new_s2.n);
579  S dir_norm = dir.squaredNorm();
580  if(dir_norm < std::numeric_limits<S>::epsilon()) // parallel
581  {
582  if((new_s1.n).dot(new_s2.n) > 0)
583  {
584  if(new_s1.d < new_s2.d)
585  {
586  penetration_depth = new_s2.d - new_s1.d;
587  ret = 1;
588  pl = new_s1;
589  return true;
590  }
591  else
592  return false;
593  }
594  else
595  {
596  if(new_s1.d + new_s2.d > 0)
597  return false;
598  else
599  {
600  penetration_depth = -(new_s1.d + new_s2.d);
601  ret = 2;
602  pl = new_s1;
603  return true;
604  }
605  }
606  }
607 
608  Vector3<S> n = new_s2.n * new_s1.d - new_s1.n * new_s2.d;
609  Vector3<S> origin = n.cross(dir);
610  origin *= (1.0 / dir_norm);
611 
612  p = origin;
613  d = dir;
614  ret = 3;
615  penetration_depth = std::numeric_limits<S>::max();
616 
617  return true;
618 }
619 
620 //==============================================================================
621 template <typename S>
622 bool halfspacePlaneIntersect(const Halfspace<S>& s1, const Transform3<S>& tf1,
623  const Plane<S>& s2, const Transform3<S>& tf2,
624  Plane<S>& pl, Vector3<S>& p, Vector3<S>& d,
625  S& penetration_depth,
626  int& ret)
627 {
628  return planeHalfspaceIntersect(s2, tf2, s1, tf1, pl, p, d, penetration_depth, ret);
629 }
630 
631 //==============================================================================
632 template <typename S>
633 bool halfspaceIntersect(const Halfspace<S>& s1, const Transform3<S>& tf1,
634  const Halfspace<S>& s2, const Transform3<S>& tf2,
635  Vector3<S>& p, Vector3<S>& d,
636  Halfspace<S>& s,
637  S& penetration_depth,
638  int& ret)
639 {
640  Halfspace<S> new_s1 = transform(s1, tf1);
641  Halfspace<S> new_s2 = transform(s2, tf2);
642 
643  ret = 0;
644 
645  Vector3<S> dir = (new_s1.n).cross(new_s2.n);
646  S dir_norm = dir.squaredNorm();
647  if(dir_norm < std::numeric_limits<S>::epsilon()) // parallel
648  {
649  if((new_s1.n).dot(new_s2.n) > 0)
650  {
651  if(new_s1.d < new_s2.d) // s1 is inside s2
652  {
653  ret = 1;
654  penetration_depth = std::numeric_limits<S>::max();
655  s = new_s1;
656  }
657  else // s2 is inside s1
658  {
659  ret = 2;
660  penetration_depth = std::numeric_limits<S>::max();
661  s = new_s2;
662  }
663  return true;
664  }
665  else
666  {
667  if(new_s1.d + new_s2.d > 0) // not collision
668  return false;
669  else // in each other
670  {
671  ret = 3;
672  penetration_depth = -(new_s1.d + new_s2.d);
673  return true;
674  }
675  }
676  }
677 
678  Vector3<S> n = new_s2.n * new_s1.d - new_s1.n * new_s2.d;
679  Vector3<S> origin = n.cross(dir);
680  origin *= (1.0 / dir_norm);
681 
682  p = origin;
683  d = dir;
684  ret = 4;
685  penetration_depth = std::numeric_limits<S>::max();
686 
687  return true;
688 }
689 
690 } // namespace detail
691 } // namespace fcl
692 
693 #endif
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
std::chrono::system_clock::time_point point
Representation of a point in time.
Definition: time.h:51