38 #ifndef FCL_SHAPE_CONVEX_INL_H 39 #define FCL_SHAPE_CONVEX_INL_H 41 #include "fcl/geometry/shape/convex.h" 53 Vector3<S>* plane_normals, S* plane_dis,
int num_planes_,
54 Vector3<S>* points,
int num_points_,
int* polygons_)
57 plane_normals = plane_normals;
58 plane_dis = plane_dis;
59 num_planes = num_planes_;
61 num_points = num_points_;
65 Vector3<S> sum = Vector3<S>::Zero();
66 for(
int i = 0; i < num_points; ++i)
71 center = sum * (S)(1.0 / num_points);
81 plane_normals = other.plane_normals;
82 plane_dis = other.plane_dis;
83 num_planes = other.num_planes;
84 points = other.points;
86 edges =
new Edge[other.num_edges];
87 memcpy(edges, other.edges,
sizeof(
Edge) * num_edges);
101 this->
aabb_local.min_.setConstant(-std::numeric_limits<S>::max());
102 this->
aabb_local.max_.setConstant(std::numeric_limits<S>::max());
103 for(
int i = 0; i < num_points; ++i)
111 template <
typename S>
118 template <
typename S>
121 Matrix3<S> C = Matrix3<S>::Zero();
123 Matrix3<S> C_canonical;
124 C_canonical << 1/ 60.0, 1/120.0, 1/120.0,
125 1/120.0, 1/ 60.0, 1/120.0,
126 1/120.0, 1/120.0, 1/ 60.0;
130 for(
int i = 0; i < num_planes; ++i)
132 Vector3<S> plane_center = Vector3<S>::Zero();
135 for(
int j = 0; j < *points_in_poly; ++j)
136 plane_center += points[index[j]];
137 plane_center = plane_center * (1.0 / *points_in_poly);
140 const Vector3<S>& v3 = plane_center;
141 for(
int j = 0; j < *points_in_poly; ++j)
143 int e_first = index[j];
144 int e_second = index[(j+1)%*points_in_poly];
145 const Vector3<S>& v1 = points[e_first];
146 const Vector3<S>& v2 = points[e_second];
147 S d_six_vol = (v1.cross(v2)).dot(v3);
152 C += A.transpose() * C_canonical * A * d_six_vol;
155 points_in_poly += (*points_in_poly + 1);
156 index = points_in_poly + 1;
159 S trace_C = C(0, 0) + C(1, 1) + C(2, 2);
162 m << trace_C - C(0, 0), -C(0, 1), -C(0, 2),
163 -C(1, 0), trace_C - C(1, 1), -C(1, 2),
164 -C(2, 0), -C(2, 1), trace_C - C(2, 2);
170 template <
typename S>
173 Vector3<S> com = Vector3<S>::Zero();
177 for(
int i = 0; i < num_planes; ++i)
179 Vector3<S> plane_center = Vector3<S>::Zero();
182 for(
int j = 0; j < *points_in_poly; ++j)
183 plane_center += points[index[j]];
184 plane_center = plane_center * (1.0 / *points_in_poly);
187 const Vector3<S>& v3 = plane_center;
188 for(
int j = 0; j < *points_in_poly; ++j)
190 int e_first = index[j];
191 int e_second = index[(j+1)%*points_in_poly];
192 const Vector3<S>& v1 = points[e_first];
193 const Vector3<S>& v2 = points[e_second];
194 S d_six_vol = (v1.cross(v2)).dot(v3);
196 com += (points[e_first] + points[e_second] + plane_center) * d_six_vol;
199 points_in_poly += (*points_in_poly + 1);
200 index = points_in_poly + 1;
203 return com / (vol * 4);
207 template <
typename S>
213 for(
int i = 0; i < num_planes; ++i)
215 Vector3<S> plane_center = Vector3<S>::Zero();
218 for(
int j = 0; j < *points_in_poly; ++j)
219 plane_center += points[index[j]];
220 plane_center = plane_center * (1.0 / *points_in_poly);
223 const Vector3<S>& v3 = plane_center;
224 for(
int j = 0; j < *points_in_poly; ++j)
226 int e_first = index[j];
227 int e_second = index[(j+1)%*points_in_poly];
228 const Vector3<S>& v1 = points[e_first];
229 const Vector3<S>& v2 = points[e_second];
230 S d_six_vol = (v1.cross(v2)).dot(v3);
234 points_in_poly += (*points_in_poly + 1);
235 index = points_in_poly + 1;
242 template <
typename S>
246 if(edges)
delete [] edges;
248 int num_edges_alloc = 0;
249 for(
int i = 0; i < num_planes; ++i)
251 num_edges_alloc += *points_in_poly;
252 points_in_poly += (*points_in_poly + 1);
255 edges =
new Edge[num_edges_alloc];
262 for(
int i = 0; i < num_planes; ++i)
264 for(
int j = 0; j < *points_in_poly; ++j)
266 e.first = std::min(index[j], index[(j+1)%*points_in_poly]);
267 e.second = std::max(index[j], index[(j+1)%*points_in_poly]);
269 for(
int k = 0; k < num_edges; ++k)
271 if((edges[k].first == e.first) && (edges[k].second == e.second))
280 edges[num_edges].first = e.first;
281 edges[num_edges].second = e.second;
286 points_in_poly += (*points_in_poly + 1);
287 index = points_in_poly + 1;
290 if(num_edges < num_edges_alloc)
293 memcpy(tmp, edges, num_edges *
sizeof(
Edge));
300 template <
typename S>
302 const Transform3<S>& tf)
const 304 std::vector<Vector3<S>> result(num_points);
305 for(
int i = 0; i < num_points; ++i)
307 result[i] = tf * points[i];
Vector3< S_ > aabb_center
AABB center in local coordinate.
Definition: collision_geometry.h:91
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18, kDOP24), basic shape (box, sphere, ellipsoid, capsule, cone, cylinder, convex, plane, halfspace, triangle), and octree
Definition: collision_geometry.h:54
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
Base class for all basic geometric shapes.
Definition: shape_base.h:48
S_ aabb_radius
AABB radius.
Definition: collision_geometry.h:94
void computeLocalAABB() override
Compute AABB<S>
Definition: convex-inl.h:99
Vector3< S > center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition: convex.h:94
Matrix3< S > computeMomentofInertia() const override
based on http://number-none.com/blow/inertia/bb_inertia.doc
Definition: convex-inl.h:119
void fillEdges()
Get edge information.
Definition: convex-inl.h:243
Vector3< S > computeCOM() const override
compute center of mass
Definition: convex-inl.h:171
std::vector< Vector3< S > > getBoundVertices(const Transform3< S > &tf) const
get the vertices of some convex shape which can bound this shape in a specific configuration ...
Definition: convex-inl.h:301
Convex(Vector3< S > *plane_normals, S *plane_dis, int num_planes, Vector3< S > *points, int num_points, int *polygons)
Constructing a convex, providing normal and offset of each polytype surface, and the points and shape...
Definition: convex-inl.h:52
AABB< S_ > aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
Definition: collision_geometry.h:97
S computeVolume() const override
compute the volume
Definition: convex-inl.h:208
Convex polytope.
Definition: convex.h:48
int * polygons
An array of indices to the points of each polygon, it should be the number of vertices followed by th...
Definition: convex.h:79
NODE_TYPE getNodeType() const override
Get node type: a conex polytope.
Definition: convex-inl.h:112