38#ifndef COAL_GEOMETRIC_SHAPES_H 39#define COAL_GEOMETRIC_SHAPES_H 44#include <boost/math/constants/constants.hpp> 79 std::invalid_argument);
154 if (other_ptr ==
nullptr)
return false;
157 return a == other.
a &&
b == other.
b &&
c == other.
c &&
162 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
176 if (
this == &other)
return *
this;
202 return (
Vec3s(s[1] + s[2], s[0] + s[2], s[0] + s[1]) / 3).asDiagonal();
218 <<
"is two small. It should be at least: " 220 std::invalid_argument);
221 return std::make_pair(
Box(2 * (
halfSide + Vec3s::Constant(value))),
227 const Box* other_ptr =
dynamic_cast<const Box*
>(&_other);
228 if (other_ptr ==
nullptr)
return false;
229 const Box& other = *other_ptr;
231 return halfSide == other.
halfSide &&
236 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
263 return I * Matrix3s::Identity();
267 return 4 * boost::math::constants::pi<CoalScalar>() *
radius *
radius *
284 <<
") is two small. It should be at least: " 286 std::invalid_argument);
292 const Sphere* other_ptr =
dynamic_cast<const Sphere*
>(&_other);
293 if (other_ptr ==
nullptr)
return false;
294 const Sphere& other = *other_ptr;
296 return radius == other.
radius &&
301 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
335 return (
Matrix3s() << 0.2 * (b2 + c2), 0, 0, 0, 0.2 * (a2 + c2), 0, 0, 0,
341 return 4 * boost::math::constants::pi<CoalScalar>() *
radii[0] *
radii[1] *
358 <<
") is two small. It should be at least: " 360 std::invalid_argument);
368 if (other_ptr ==
nullptr)
return false;
371 return radii == other.
radii &&
376 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
411 return boost::math::constants::pi<CoalScalar>() *
radius *
radius *
417 boost::math::constants::pi<CoalScalar>();
419 boost::math::constants::pi<CoalScalar>() * 4 / 3.0;
427 return (
Matrix3s() << ix, 0, 0, 0, ix, 0, 0, 0, iz).finished();
443 <<
") is two small. It should be at least: " 445 std::invalid_argument);
453 if (other_ptr ==
nullptr)
return false;
454 const Capsule& other = *other_ptr;
461 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
495 return boost::math::constants::pi<CoalScalar>() *
radius *
radius *
505 return (
Matrix3s() << ix, 0, 0, 0, ix, 0, 0, 0, iz).finished();
525 <<
") is two small. It should be at least: " 527 std::invalid_argument);
532 tan_alpha / std::sqrt(1 + tan_alpha * tan_alpha);
533 const CoalScalar top_inflation = value / sin_alpha;
537 const CoalScalar new_cz = (top_inflation + bottom_inflation) / 2.;
538 const CoalScalar new_radius = new_lz / tan_alpha;
540 return std::make_pair(
Cone(new_radius, new_lz),
546 const Cone* other_ptr =
dynamic_cast<const Cone*
>(&_other);
547 if (other_ptr ==
nullptr)
return false;
548 const Cone& other = *other_ptr;
555 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
573 if (
this == &other)
return *
this;
575 this->radius = other.
radius;
596 return boost::math::constants::pi<CoalScalar>() *
radius *
radius *
604 return (
Matrix3s() << ix, 0, 0, 0, ix, 0, 0, 0, iz).finished();
622 <<
") is two small. It should be at least: " 624 std::invalid_argument);
632 if (other_ptr ==
nullptr)
return false;
640 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
661 const char* qhullCommand = NULL);
666 const char* qhullCommand = NULL);
684 void buildDoubleDescription();
704 for (
int i = 0; i <
count_; ++i) {
705 if (
n_[i] != other.
n_[i])
return false;
719 std::shared_ptr<std::vector<Vec3s>>
points;
775 unsigned int num_points_);
782 void set(std::shared_ptr<std::vector<Vec3s>> points_,
783 unsigned int num_points_);
790 void buildDoubleDescriptionFromQHullResult(
const orgQhull::Qhull& qh);
804 void computeCenter();
808 if (other_ptr ==
nullptr)
return false;
817 const std::vector<Vec3s>& points_ = *
points;
818 const std::vector<Vec3s>& other_points_ = *(other.
points);
819 for (
unsigned int i = 0; i <
num_points; ++i) {
820 if (points_[i] != (other_points_)[i])
return false;
824 if ((!(neighbors.get()) && other.
neighbors.get()) ||
825 (neighbors.get() && !(other.
neighbors.get())))
827 if (neighbors.get() && other.
neighbors.get()) {
828 const std::vector<Neighbors>& neighbors_ = *neighbors;
829 const std::vector<Neighbors>& other_neighbors_ = *(other.
neighbors);
830 for (
unsigned int i = 0; i < num_points; ++i) {
831 if (neighbors_[i] != other_neighbors_[i])
return false;
835 if ((!(normals.get()) && other.
normals.get()) ||
836 (normals.get() && !(other.
normals.get())))
838 if (normals.get() && other.
normals.get()) {
839 const std::vector<Vec3s>& normals_ = *normals;
840 const std::vector<Vec3s>& other_normals_ = *(other.
normals);
841 for (
unsigned int i = 0; i < num_normals_and_offsets; ++i) {
842 if (normals_[i] != other_normals_[i])
return false;
846 if ((!(offsets.get()) && other.
offsets.get()) ||
847 (offsets.get() && !(other.
offsets.get())))
849 if (offsets.get() && other.
offsets.get()) {
850 const std::vector<double>& offsets_ = *offsets;
851 const std::vector<double>& other_offsets_ = *(other.
offsets);
852 for (
unsigned int i = 0; i < num_normals_and_offsets; ++i) {
853 if (offsets_[i] != other_offsets_[i])
return false;
857 if (this->support_warm_starts.
points.size() !=
859 this->support_warm_starts.indices.size() !=
864 for (
size_t i = 0; i < this->support_warm_starts.
points.size(); ++i) {
865 if (this->support_warm_starts.
points[i] !=
867 this->support_warm_starts.indices[i] !=
873 return center == other.
center &&
878 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
881template <
typename PolygonT>
935 return std::numeric_limits<CoalScalar>::lowest();
949 <<
") is two small. It should be at least: " 951 std::invalid_argument);
968 if (other_ptr ==
nullptr)
return false;
971 return n == other.
n &&
d == other.
d &&
976 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1017 if (signed_dist >= 0) {
1018 return -signed_dist;
1024 return std::abs(std::abs(
n.dot(p) -
d) - this->getSweptSphereRadius());
1045 const Plane* other_ptr =
dynamic_cast<const Plane*
>(&_other);
1046 if (other_ptr ==
nullptr)
return false;
1047 const Plane& other = *other_ptr;
1049 return n == other.
n &&
d == other.
d &&
1054 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Center at zero point, axis aligned box.
Definition geometric_shapes.h:166
Capsule It is where is the distance between the point x and the capsule segment AB,...
Definition geometric_shapes.h:383
The geometry for the object for collision or distance computation.
Definition collision_object.h:94
Cone The base of the cone is at and the top is at .
Definition geometric_shapes.h:467
Convex polytope.
Definition convex.h:49
Cylinder along Z axis. The cylinder is defined at its centroid.
Definition geometric_shapes.h:560
Ellipsoid centered at point zero.
Definition geometric_shapes.h:305
Center at zero point sphere.
Definition geometric_shapes.h:240
#define COAL_THROW_PRETTY(message, exception)
Definition fwd.hh:64
@ GEOM_CONE
Definition collision_object.h:77
@ GEOM_TRIANGLE
Definition collision_object.h:82
@ GEOM_BOX
Definition collision_object.h:74
@ GEOM_SPHERE
Definition collision_object.h:75
@ GEOM_CYLINDER
Definition collision_object.h:78
@ GEOM_CAPSULE
Definition collision_object.h:76
@ GEOM_ELLIPSOID
Definition collision_object.h:84
@ GEOM_HALFSPACE
Definition collision_object.h:81
@ GEOM_PLANE
Definition collision_object.h:80
@ GEOM_CONVEX
Definition collision_object.h:79
@ OT_GEOM
Definition collision_object.h:55
CollisionGeometry()
Definition collision_object.h:96
CoalScalar halfLength
Half Length along z axis.
Definition geometric_shapes.h:486
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition geometric_shapes.h:600
std::shared_ptr< std::vector< double > > offsets
An array of the offsets to the normals of the polygon. Note: there are as many offsets as normals.
Definition geometric_shapes.h:726
CoalScalar minInflationValue() const
Definition geometric_shapes.h:607
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition geometric_shapes.h:415
void set(std::shared_ptr< std::vector< Vec3s > > points_, unsigned int num_points_)
Set the points of the convex shape.
virtual Halfspace * clone() const
Clone *this into a new Halfspace.
Definition geometric_shapes.h:918
virtual ~ShapeBase()
Definition geometric_shapes.h:69
Cone(CoalScalar radius_, CoalScalar lz_)
Definition geometric_shapes.h:472
std::pair< Ellipsoid, Transform3s > inflated(const CoalScalar value) const
Inflate the ellipsoid by an amount given by value. This value can be positive or negative but must al...
Definition geometric_shapes.h:355
virtual Plane * clone() const
Clone *this into a new Plane.
Definition geometric_shapes.h:1008
CoalScalar computeVolume() const
compute the volume
Definition geometric_shapes.h:197
ShapeBase(const ShapeBase &other)
 
Definition geometric_shapes.h:63
Vec3s n
Plane normal.
Definition geometric_shapes.h:956
std::shared_ptr< std::vector< unsigned int > > nneighbors_
Array of indices of the neighbors of each vertex. Since we don't know a priori the number of neighbor...
Definition geometric_shapes.h:801
unsigned int * n_
Definition geometric_shapes.h:689
virtual TriangleP * clone() const
Clone *this into a new TriangleP.
Definition geometric_shapes.h:121
Halfspace & operator=(const Halfspace &other)
operator =
Definition geometric_shapes.h:911
std::pair< Box, Transform3s > inflated(const CoalScalar value) const
Inflate the box by an amount given by value. This value can be positive or negative but must always >...
Definition geometric_shapes.h:215
bool operator==(const Neighbors &other) const
Definition geometric_shapes.h:701
Plane()
Definition geometric_shapes.h:996
virtual Ellipsoid * clone() const
Clone *this into a new Ellipsoid.
Definition geometric_shapes.h:318
std::pair< Cone, Transform3s > inflated(const CoalScalar value) const
Inflate the cone by an amount given by value. This value can be positive or negative but must always ...
Definition geometric_shapes.h:522
CoalScalar radius
Radius of the sphere.
Definition geometric_shapes.h:253
CoalScalar minInflationValue() const
Definition geometric_shapes.h:345
Capsule(const Capsule &other)
Definition geometric_shapes.h:392
bool operator!=(const Neighbors &other) const
Definition geometric_shapes.h:711
Vec3s n
Plane normal.
Definition geometric_shapes.h:1034
CoalScalar distance(const Vec3s &p) const
Definition geometric_shapes.h:924
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition geometric_shapes.h:261
Box()
Default constructor.
Definition geometric_shapes.h:186
Sphere(const Sphere &other)
Definition geometric_shapes.h:247
void computeLocalAABB()
Compute AABB.
unsigned char const & count() const
Definition geometric_shapes.h:691
CoalScalar radius
Radius of the cone.
Definition geometric_shapes.h:483
CoalScalar computeVolume() const
compute the volume
Definition geometric_shapes.h:595
Halfspace(CoalScalar a, CoalScalar b, CoalScalar c, CoalScalar d_)
Construct a plane with normal direction and offset.
Definition geometric_shapes.h:900
Ellipsoid(CoalScalar rx, CoalScalar ry, CoalScalar rz)
Definition geometric_shapes.h:310
Plane & operator=(const Plane &other)
operator =
Definition geometric_shapes.h:1001
Box & operator=(const Box &other)
Definition geometric_shapes.h:175
std::shared_ptr< std::vector< Vec3s > > normals
An array of the normals of the polygon.
Definition geometric_shapes.h:723
Ellipsoid(const Ellipsoid &other)
Definition geometric_shapes.h:315
CoalScalar computeVolume() const
compute the volume
Definition geometric_shapes.h:340
NODE_TYPE getNodeType() const
get the node type
Definition geometric_shapes.h:126
TriangleP(const TriangleP &other)
Definition geometric_shapes.h:117
static ConvexBase * convexHull(std::shared_ptr< std::vector< Vec3s > > &points, unsigned int num_points, bool keepTriangles, const char *qhullCommand=NULL)
Build a convex hull based on Qhull library and store the vertices and optionally the triangles.
Cylinder()
Default constructor.
Definition geometric_shapes.h:563
void computeLocalAABB()
Compute AABB.
Ellipsoid()
Default constructor.
Definition geometric_shapes.h:308
unsigned int num_points
Definition geometric_shapes.h:720
void computeLocalAABB()
Compute AABB.
Plane(const Plane &other)
Definition geometric_shapes.h:998
std::pair< Cylinder, Transform3s > inflated(const CoalScalar value) const
Inflate the cylinder by an amount given by value. This value can be positive or negative but must alw...
Definition geometric_shapes.h:619
CoalScalar computeVolume() const
compute the volume
Definition geometric_shapes.h:266
CoalScalar halfLength
Half Length along z axis.
Definition geometric_shapes.h:587
Plane(CoalScalar a, CoalScalar b, CoalScalar c, CoalScalar d_)
Construct a plane with normal direction and offset.
Definition geometric_shapes.h:991
void buildSupportWarmStart()
Build the support points warm starts.
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition geometric_shapes.h:330
Halfspace(const Halfspace &other)
Definition geometric_shapes.h:907
CoalScalar minInflationValue() const
Definition geometric_shapes.h:205
NODE_TYPE getNodeType() const
Get node type: an ellipsoid.
Definition geometric_shapes.h:328
NODE_TYPE getNodeType() const
Get node type: a cone.
Definition geometric_shapes.h:492
std::shared_ptr< std::vector< Neighbors > > neighbors
Neighbors of each vertex. It is an array of size num_points. For each vertex, it contains the number ...
Definition geometric_shapes.h:732
Ellipsoid(const Vec3s &radii)
Definition geometric_shapes.h:313
void computeLocalAABB()
Compute AABB.
Vec3s halfSide
box side half-length
Definition geometric_shapes.h:189
Halfspace()
Definition geometric_shapes.h:905
static constexpr size_t num_support_warm_starts
Number of support warm starts.
Definition geometric_shapes.h:754
CoalScalar distance(const Vec3s &p) const
Definition geometric_shapes.h:1023
static constexpr size_t num_vertices_large_convex_threshold
Above this threshold, the convex polytope is considered large. This influcences the way the support f...
Definition geometric_shapes.h:716
CoalScalar m_swept_sphere_radius
Radius of the sphere swept around the shape. Default value is 0. Note: this property differs from inf...
Definition geometric_shapes.h:102
Sphere()
Default constructor.
Definition geometric_shapes.h:243
void setSweptSphereRadius(CoalScalar radius)
Set radius of sphere swept around the shape. Must be >= 0.
Definition geometric_shapes.h:76
NODE_TYPE getNodeType() const
Get node type: a convex polytope.
Definition geometric_shapes.h:679
Sphere(CoalScalar radius_)
Definition geometric_shapes.h:245
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition geometric_shapes.h:199
Vec3s a
Definition geometric_shapes.h:149
unsigned int const & operator[](int i) const
Definition geometric_shapes.h:696
OBJECT_TYPE getObjectType() const
Get object type: a geometric shape.
Definition geometric_shapes.h:72
Halfspace(const Vec3s &n_, CoalScalar d_)
Construct a half space with normal direction and offset.
Definition geometric_shapes.h:895
void computeLocalAABB()
Compute AABB.
Vec3s b
Definition geometric_shapes.h:149
virtual Box * clone() const
Clone *this into a new Box.
Definition geometric_shapes.h:183
void computeLocalAABB()
Compute AABB.
ShapeBase & operator=(const ShapeBase &other)=default
Plane(const Vec3s &n_, CoalScalar d_)
Construct a plane with normal direction and offset.
Definition geometric_shapes.h:986
void unitNormalTest()
Turn non-unit normal into unit.
void computeLocalAABB()
Compute AABB.
void initialize(std::shared_ptr< std::vector< Vec3s > > points_, unsigned int num_points_)
Initialize the points of the convex shape This also initializes the ConvexBase::center.
CoalScalar getSweptSphereRadius() const
Get radius of sphere swept around the shape. This radius is always >= 0.
Definition geometric_shapes.h:86
void computeLocalAABB()
Compute AABB.
CoalScalar signedDistance(const Vec3s &p) const
Definition geometric_shapes.h:1010
Box(CoalScalar x, CoalScalar y, CoalScalar z)
Definition geometric_shapes.h:168
Vec3s computeCOM() const
compute center of mass
Definition geometric_shapes.h:508
std::vector< int > indices
Indices of the support points warm starts. These are the indices of the real convex,...
Definition geometric_shapes.h:750
Vec3s radii
Radii of the Ellipsoid (such that on boundary: x^2/rx^2 + y^2/ry^2.
Definition geometric_shapes.h:322
std::pair< Capsule, Transform3s > inflated(const CoalScalar value) const
Inflate the capsule by an amount given by value. This value can be positive or negative but must alwa...
Definition geometric_shapes.h:440
Cylinder(const Cylinder &other)
Definition geometric_shapes.h:569
virtual Cone * clone() const
Clone *this into a new Cone.
Definition geometric_shapes.h:480
Vec3s c
Definition geometric_shapes.h:149
NODE_TYPE getNodeType() const
Get node type: a sphere.
Definition geometric_shapes.h:259
virtual Cylinder * clone() const
Clone *this into a new Cylinder.
Definition geometric_shapes.h:581
virtual Capsule * clone() const
Clone *this into a new Capsule.
Definition geometric_shapes.h:396
CoalScalar computeVolume() const
compute the volume
Definition geometric_shapes.h:410
Cylinder(CoalScalar radius_, CoalScalar lz_)
Definition geometric_shapes.h:565
CoalScalar signedDistance(const Vec3s &p) const
Definition geometric_shapes.h:920
std::vector< Vec3s > points
Array of support points to warm start the support function computation.
Definition geometric_shapes.h:745
CoalScalar radius
Radius of capsule.
Definition geometric_shapes.h:399
unsigned int num_normals_and_offsets
Definition geometric_shapes.h:727
CoalScalar minInflationValue() const
Definition geometric_shapes.h:271
CoalScalar d
Plane offset.
Definition geometric_shapes.h:1037
Box(const Vec3s &side_)
Definition geometric_shapes.h:171
void unitNormalTest()
Turn non-unit normal into unit.
Vec3s center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition geometric_shapes.h:736
unsigned char count_
Definition geometric_shapes.h:688
ConvexBase()
Construct an uninitialized convex object Initialization is done with ConvexBase::initialize.
Definition geometric_shapes.h:762
void computeLocalAABB()
virtual function of compute AABB in local coordinate
NODE_TYPE getNodeType() const
Get node type: a cylinder.
Definition geometric_shapes.h:593
ShapeBase()
Definition geometric_shapes.h:60
static ConvexBase * convexHull(const Vec3s *points, unsigned int num_points, bool keepTriangles, const char *qhullCommand=NULL)
Matrix3s computeMomentofInertia() const
compute the inertia matrix, related to the origin
Definition geometric_shapes.h:499
CoalScalar halfLength
Half Length along z axis.
Definition geometric_shapes.h:402
CoalScalar radius
Radius of the cylinder.
Definition geometric_shapes.h:584
Box(const Box &other)
Definition geometric_shapes.h:173
TriangleP()
Definition geometric_shapes.h:112
virtual Sphere * clone() const
Clone *this into a new Sphere.
Definition geometric_shapes.h:250
std::shared_ptr< std::vector< Vec3s > > points
An array of the points of the polygon.
Definition geometric_shapes.h:719
Capsule()
Default constructor.
Definition geometric_shapes.h:386
std::pair< Halfspace, Transform3s > inflated(const CoalScalar value) const
Inflate the halfspace by an amount given by value. This value can be positive or negative but must al...
Definition geometric_shapes.h:946
unsigned int & operator[](int i)
Definition geometric_shapes.h:692
NODE_TYPE getNodeType() const
Get node type: a half space.
Definition geometric_shapes.h:932
TriangleP(const Vec3s &a_, const Vec3s &b_, const Vec3s &c_)
Definition geometric_shapes.h:114
Cylinder & operator=(const Cylinder &other)
Definition geometric_shapes.h:572
Cone()
Default constructor.
Definition geometric_shapes.h:470
ConvexBase(const ConvexBase &other)
Copy constructor Only the list of neighbors is copied.
NODE_TYPE getNodeType() const
Get node type: a plane.
Definition geometric_shapes.h:1031
SupportWarmStartPolytope support_warm_starts
Support warm start polytopes.
Definition geometric_shapes.h:757
Cone(const Cone &other)
Definition geometric_shapes.h:476
CoalScalar minInflationValue() const
Definition geometric_shapes.h:510
std::pair< Sphere, Transform3s > inflated(const CoalScalar value) const
Inflate the sphere by an amount given by value. This value can be positive or negative but must alway...
Definition geometric_shapes.h:281
virtual ConvexBase * clone() const
Clone (deep copy). This method is consistent with BVHModel clone method. The copy constructor is call...
Definition geometric_shapes.h:673
Capsule(CoalScalar radius_, CoalScalar lz_)
Definition geometric_shapes.h:388
CoalScalar d
Plane offset.
Definition geometric_shapes.h:959
NODE_TYPE getNodeType() const
Get node type: a box.
Definition geometric_shapes.h:195
CoalScalar computeVolume() const
compute the volume
Definition geometric_shapes.h:494
void computeLocalAABB()
Compute AABB.
NODE_TYPE getNodeType() const
Get node type: a capsule.
Definition geometric_shapes.h:408
CoalScalar minInflationValue() const
Definition geometric_shapes.h:430
CoalScalar minInflationValue() const
Definition geometric_shapes.h:934
Main namespace.
Definition broadphase_bruteforce.h:44
Eigen::Matrix< CoalScalar, 3, 3 > Matrix3s
Definition data_types.h:81
bool isEqual(const Eigen::MatrixBase< Derived > &lhs, const Eigen::MatrixBase< OtherDerived > &rhs, const CoalScalar tol=std::numeric_limits< CoalScalar >::epsilon() *100)
Definition tools.h:204
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition collision_object.h:64
OBJECT_TYPE
object type: BVH (mesh, points), basic geometry, octree
Definition collision_object.h:52
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition data_types.h:77
double CoalScalar
Definition data_types.h:76
Definition geometric_shapes.h:687
The support warm start polytope contains certain points of this which are support points in specific ...
Definition geometric_shapes.h:742