Collision Checker
utils.h
Go to the documentation of this file.
1 #ifndef CPP_COLLISION_INCLUDE_COLLISION_NARROWPHASE_UTILS_H_
2 #define CPP_COLLISION_INCLUDE_COLLISION_NARROWPHASE_UTILS_H_
3 
6 
7 namespace collision {
8 
10  Eigen::Vector2d pt2,
11  double rect_width) {
12  Eigen::Matrix2d local_axes;
13 
14  Eigen::Vector2d v = pt2 - pt1;
15 
16  Eigen::Vector2d center = (pt1 + pt2) / 2;
17 
18  double length = v.norm();
19 
20  if (length < 1e-10) return 0;
21 
22  v = v / length;
23 
24  local_axes.col(0) = v;
25  local_axes.col(1) = Eigen::Vector2d(-v(1), v(0));
26  return std::make_shared<const RectangleOBB>(length / 2, rect_width / 2,
27  local_axes, center);
28 }
29 
30 int generate_rectangles_from_vertex_list(std::vector<Eigen::Vector2d> &verts,
31  collision::ShapeGroup *sg_rects_ptr,
32  double rect_width) {
33  for (auto vert = verts.begin(); vert < verts.end() - 1; vert++) {
35  collision::create_obb_from_points(*vert, *(vert + 1), rect_width);
36  if (rect_new) sg_rects_ptr->addToGroup(rect_new);
37  }
38  if (verts.size() > 1) {
40  collision::create_obb_from_points(*(verts.end() - 1), *(verts.begin()),
41  rect_width);
42  if (rect_new) sg_rects_ptr->addToGroup(rect_new);
43  }
44  return 0;
45 }
46 } // namespace collision
47 
48 #endif /* CPP_COLLISION_INCLUDE_COLLISION_NARROWPHASE_UTILS_H_ */
RectangleOBBConstPtr create_obb_from_points(Eigen::Vector2d pt1, Eigen::Vector2d pt2, double rect_width)
Definition: utils.h:9
ShapeGroup can contain simple shapes.
Definition: shape_group.h:33
std::shared_ptr< const RectangleOBB > RectangleOBBConstPtr
int generate_rectangles_from_vertex_list(std::vector< Eigen::Vector2d > &verts, collision::ShapeGroup *sg_rects_ptr, double rect_width)
Definition: utils.h:30
void addToGroup(ShapeConstPtr shape)
Adds a simple shape to the ShapeGroup.
Definition: shape_group.cc:176