triangle_triangle.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2024, INRIA
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Open Source Robotics Foundation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
38 
40 #include "../narrowphase/details.h"
41 
42 namespace coal {
43 
44 namespace internal {
45 template <>
47  const CollisionGeometry* o1, const Transform3s& tf1,
48  const CollisionGeometry* o2, const Transform3s& tf2,
49  const GJKSolver* solver, const bool, Vec3s& p1, Vec3s& p2, Vec3s& normal) {
50  // Transform the triangles in world frame
51  const TriangleP& s1 = static_cast<const TriangleP&>(*o1);
52  const TriangleP t1(tf1.transform(s1.a), tf1.transform(s1.b),
53  tf1.transform(s1.c));
54 
55  const TriangleP& s2 = static_cast<const TriangleP&>(*o2);
56  const TriangleP t2(tf2.transform(s2.a), tf2.transform(s2.b),
57  tf2.transform(s2.c));
58 
59  // Reset GJK algorithm
60  // We don't need to take into account swept-sphere radius in GJK iterations;
61  // the result will be corrected after GJK terminates.
62  solver->minkowski_difference
64  solver->gjk.reset(solver->gjk_max_iterations, solver->gjk_tolerance);
65 
66  // Get GJK initial guess
67  Vec3s guess;
69  solver->enable_cached_guess) {
70  guess = solver->cached_guess;
71  } else {
72  guess = (t1.a + t1.b + t1.c - t2.a - t2.b - t2.c) / 3;
73  }
74  support_func_guess_t support_hint;
75  solver->epa.status =
76  details::EPA::DidNotRun; // EPA is never called in this function
77 
78  details::GJK::Status gjk_status =
79  solver->gjk.evaluate(solver->minkowski_difference, guess, support_hint);
80 
81  solver->cached_guess = solver->gjk.getGuessFromSimplex();
82  solver->support_func_cached_guess = solver->gjk.support_hint;
83 
84  // Retrieve witness points and normal
86  normal);
87  CoalScalar distance = solver->gjk.distance;
88 
89  if (gjk_status == details::GJK::Collision) {
90  CoalScalar penetrationDepth =
91  details::computePenetration(t1.a, t1.b, t1.c, t2.a, t2.b, t2.c, normal);
92  distance = -penetrationDepth;
93  } else {
94  // No collision
95  // TODO On degenerated case, the closest point may be wrong
96  // (i.e. an object face normal is colinear to gjk.ray
97  // assert (dist == (w0 - w1).norm());
98  assert(solver->gjk.ray.norm() > solver->gjk.getTolerance());
99  }
100  // assert(false && "should not reach this point");
101  // return false;
102 
103  return distance;
104 }
105 } // namespace internal
106 
107 } // namespace coal
coal::details::GJK::getWitnessPointsAndNormal
void getWitnessPointsAndNormal(const MinkowskiDiff &shape, Vec3s &w0, Vec3s &w1, Vec3s &normal) const
Definition: src/narrowphase/gjk.cpp:176
coal::TriangleP::b
Vec3s b
Definition: coal/shape/geometric_shapes.h:149
coal::GJKSolver::gjk
EIGEN_MAKE_ALIGNED_OPERATOR_NEW details::GJK gjk
GJK algorithm.
Definition: coal/narrowphase/narrowphase.h:62
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal::details::GJK::ray
Vec3s ray
Definition: coal/narrowphase/gjk.h:111
coal::GJKSolver::gjk_max_iterations
size_t gjk_max_iterations
maximum number of iterations of GJK
Definition: coal/narrowphase/narrowphase.h:65
coal::details::GJK::Status
Status
Status of the GJK algorithm: DidNotRun: GJK has not been run. Failed: GJK did not converge (it exceed...
Definition: coal/narrowphase/gjk.h:94
gjk.tf1
tuple tf1
Definition: test/scripts/gjk.py:27
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::details::NoSweptSphere
@ NoSweptSphere
Definition: coal/narrowphase/support_functions.h:59
coal::CachedGuess
@ CachedGuess
Definition: coal/data_types.h:95
coal::GJKSolver
collision and distance solver based on the GJK and EPA algorithms. Originally, GJK and EPA were imple...
Definition: coal/narrowphase/narrowphase.h:57
coal::distance
COAL_DLLAPI CoalScalar distance(const Matrix3s &R0, const Vec3s &T0, const kIOS &b1, const kIOS &b2, Vec3s *P=NULL, Vec3s *Q=NULL)
Approximate distance between two kIOS bounding volumes.
Definition: kIOS.cpp:180
coal::GJKSolver::enable_cached_guess
bool enable_cached_guess
Whether smart guess can be provided @Deprecated Use gjk_initial_guess instead.
Definition: coal/narrowphase/narrowphase.h:76
coal::details::GJK::reset
void reset(size_t max_iterations_, CoalScalar tolerance_)
resets the GJK algorithm, preparing it for a new run. Other than the maximum number of iterations and...
Definition: src/narrowphase/gjk.cpp:58
coal::CollisionGeometry
The geometry for the object for collision or distance computation.
Definition: coal/collision_object.h:94
coal::Transform3s
Simple transform class used locally by InterpMotion.
Definition: coal/math/transform.h:55
shape_shape_func.h
coal::support_func_guess_t
Eigen::Vector2i support_func_guess_t
Definition: coal/data_types.h:87
coal::TriangleP::a
Vec3s a
Definition: coal/shape/geometric_shapes.h:149
t2
dictionary t2
coal::details::EPA::DidNotRun
@ DidNotRun
Definition: coal/narrowphase/gjk.h:330
coal::GJKSolver::support_func_cached_guess
support_func_guess_t support_func_cached_guess
smart guess for the support function
Definition: coal/narrowphase/narrowphase.h:82
coal::details::GJK::distance
CoalScalar distance
The distance between the two shapes, computed by GJK. If the distance is below GJK's threshold,...
Definition: coal/narrowphase/gjk.h:118
gjk.tf2
tuple tf2
Definition: test/scripts/gjk.py:36
coal::details::EPA::status
Status status
Definition: coal/narrowphase/gjk.h:343
coal::GJKSolver::epa
details::EPA epa
EPA algorithm.
Definition: coal/narrowphase/narrowphase.h:98
octree.p1
tuple p1
Definition: octree.py:54
coal::details::computePenetration
CoalScalar computePenetration(const Vec3s &P1, const Vec3s &P2, const Vec3s &P3, const Vec3s &Q1, const Vec3s &Q2, const Vec3s &Q3, Vec3s &normal)
See the prototype below.
Definition: details.h:703
coal::TriangleP
Triangle stores the points instead of only indices of points.
Definition: coal/shape/geometric_shapes.h:110
coal::internal::ShapeShapeDistance< TriangleP, TriangleP >
CoalScalar ShapeShapeDistance< TriangleP, TriangleP >(const CollisionGeometry *o1, const Transform3s &tf1, const CollisionGeometry *o2, const Transform3s &tf2, const GJKSolver *solver, const bool, Vec3s &p1, Vec3s &p2, Vec3s &normal)
Definition: triangle_triangle.cpp:46
coal::GJKSolver::cached_guess
Vec3s cached_guess
smart guess
Definition: coal/narrowphase/narrowphase.h:79
coal::details::GJK::getGuessFromSimplex
Vec3s getGuessFromSimplex() const
get the guess from current simplex
Definition: src/narrowphase/gjk.cpp:70
coal::details::MinkowskiDiff::set
void set(const ShapeBase *shape0, const ShapeBase *shape1)
Set the two shapes, assuming the relative transformation between them is identity....
Definition: minkowski_difference.cpp:293
coal::GJKSolver::minkowski_difference
details::MinkowskiDiff minkowski_difference
Minkowski difference used by GJK and EPA algorithms.
Definition: coal/narrowphase/narrowphase.h:107
coal::details::GJK::getTolerance
CoalScalar getTolerance() const
Get the tolerance of GJK.
Definition: coal/narrowphase/gjk.h:207
coal::details::GJK::evaluate
Status evaluate(const MinkowskiDiff &shape, const Vec3s &guess, const support_func_guess_t &supportHint=support_func_guess_t::Zero())
GJK algorithm, given the initial value guess.
Definition: src/narrowphase/gjk.cpp:187
geometric_shapes.h
coal::TriangleP::c
Vec3s c
Definition: coal/shape/geometric_shapes.h:149
coal::details::GJK::Collision
@ Collision
Definition: coal/narrowphase/gjk.h:100
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::details::GJK::support_hint
support_func_guess_t support_hint
Definition: coal/narrowphase/gjk.h:112
coal::GJKSolver::gjk_tolerance
CoalScalar gjk_tolerance
tolerance of GJK
Definition: coal/narrowphase/narrowphase.h:68
coal::GJKSolver::gjk_initial_guess
GJKInitialGuess gjk_initial_guess
which warm start to use for GJK
Definition: coal/narrowphase/narrowphase.h:71


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:59