38 #ifndef FCL_NARROWPHASE_DETAIL_MINKOWSKIDIFF_INL_H 39 #define FCL_NARROWPHASE_DETAIL_MINKOWSKIDIFF_INL_H 41 #include "fcl/narrowphase/detail/convexity_based_algorithm/minkowski_diff.h" 43 #include "fcl/geometry/shape/box.h" 44 #include "fcl/geometry/shape/capsule.h" 45 #include "fcl/geometry/shape/cone.h" 46 #include "fcl/geometry/shape/convex.h" 47 #include "fcl/geometry/shape/cylinder.h" 48 #include "fcl/geometry/shape/ellipsoid.h" 49 #include "fcl/geometry/shape/halfspace.h" 50 #include "fcl/geometry/shape/plane.h" 51 #include "fcl/geometry/shape/sphere.h" 52 #include "fcl/geometry/shape/triangle_p.h" 62 struct MinkowskiDiff<double>;
65 template <
typename S,
typename Derived>
66 Vector3<S> getSupport(
67 const ShapeBase<S>* shape,
68 const Eigen::MatrixBase<Derived>& dir)
72 Derived::RowsAtCompileTime == 3
73 && Derived::ColsAtCompileTime == 1,
74 THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
76 switch(shape->getNodeType())
80 const auto* triangle =
static_cast<const TriangleP<S>*
>(shape);
81 S dota = dir.dot(triangle->a);
82 S dotb = dir.dot(triangle->b);
83 S dotc = dir.dot(triangle->c);
102 const Box<S>* box =
static_cast<const Box<S>*
>(shape);
103 return Vector3<S>((dir[0]>0)?(box->side[0]/2):(-box->side[0]/2),
104 (dir[1]>0)?(box->side[1]/2):(-box->side[1]/2),
105 (dir[2]>0)?(box->side[2]/2):(-box->side[2]/2));
110 const Sphere<S>* sphere =
static_cast<const Sphere<S>*
>(shape);
111 return dir * sphere->radius;
116 const Ellipsoid<S>* ellipsoid =
static_cast<const Ellipsoid<S>*
>(shape);
118 const S a2 = ellipsoid->radii[0] * ellipsoid->radii[0];
119 const S b2 = ellipsoid->radii[1] * ellipsoid->radii[1];
120 const S c2 = ellipsoid->radii[2] * ellipsoid->radii[2];
122 const Vector3<S> v(a2 * dir[0], b2 * dir[1], c2 * dir[2]);
123 const S d = std::sqrt(v.dot(dir));
130 const Capsule<S>* capsule =
static_cast<const Capsule<S>*
>(shape);
131 S half_h = capsule->lz * 0.5;
132 Vector3<S> pos1(0, 0, half_h);
133 Vector3<S> pos2(0, 0, -half_h);
134 Vector3<S> v = dir * capsule->radius;
137 if(dir.dot(pos1) > dir.dot(pos2))
144 const Cone<S>* cone =
static_cast<const Cone<S>*
>(shape);
145 S zdist = dir[0] * dir[0] + dir[1] * dir[1];
146 S len = zdist + dir[2] * dir[2];
147 zdist = std::sqrt(zdist);
148 len = std::sqrt(len);
149 S half_h = cone->lz * 0.5;
150 S radius = cone->radius;
152 S sin_a = radius / std::sqrt(radius * radius + 4 * half_h * half_h);
154 if(dir[2] > len * sin_a)
155 return Vector3<S>(0, 0, half_h);
158 S rad = radius / zdist;
159 return Vector3<S>(rad * dir[0], rad * dir[1], -half_h);
162 return Vector3<S>(0, 0, -half_h);
167 const Cylinder<S>* cylinder =
static_cast<const Cylinder<S>*
>(shape);
168 S zdist = std::sqrt(dir[0] * dir[0] + dir[1] * dir[1]);
169 S half_h = cylinder->lz * 0.5;
172 return Vector3<S>(0, 0, (dir[2]>0)? half_h:-half_h);
176 S d = cylinder->radius / zdist;
177 return Vector3<S>(d * dir[0], d * dir[1], (dir[2]>0)?half_h:-half_h);
183 const Convex<S>* convex =
static_cast<const Convex<S>*
>(shape);
184 S maxdot = - std::numeric_limits<S>::max();
185 Vector3<S>* curp = convex->points;
186 Vector3<S> bestv = Vector3<S>::Zero();
187 for(
int i = 0; i < convex->num_points; ++i, curp+=1)
189 S dot = dir.dot(*curp);
205 return Vector3<S>::Zero();
209 template <
typename S>
210 MinkowskiDiff<S>::MinkowskiDiff()
216 template <
typename S>
219 return getSupport(shapes[0], d);
223 template <
typename S>
226 return toshape0 * getSupport(shapes[1], toshape1 * d);
230 template <
typename S>
233 return support0(d) - support1(-d);
237 template <
typename S>
247 template <
typename S>
251 return getSupport(shapes[0], d);
253 return getSupport(shapes[0], d) + v;
257 template <
typename S>
260 return support0(d, v) - support1(-d);
264 template <
typename S>
270 return support0(d, v);
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
Vector3< S > support(const Vector3< S > &d) const
support function for the pair of shapes
Definition: minkowski_diff-inl.h:231
Vector3< S > support0(const Vector3< S > &d) const
support function for shape0
Definition: minkowski_diff-inl.h:217
Vector3< S > support1(const Vector3< S > &d) const
support function for shape1
Definition: minkowski_diff-inl.h:224