Collision Checker
triangle_sat2d.h
Go to the documentation of this file.
1 #pragma once
2 #include <Eigen/Dense>
4 
5 namespace collision {
6 namespace detail {
8  public:
9  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
10  Triangle_SAT2D(const Triangle& tri) {
11  corner.col(0) = tri.v1();
12  corner.col(1) = tri.v2();
13  corner.col(2) = tri.v3();
14 
15  // axes computation
16 
17  axes.col(0) = normal_vector(corner.col(1) - corner.col(0));
18  axes.col(1) = normal_vector(corner.col(2) - corner.col(0));
19  axes.col(2) = normal_vector(corner.col(2) - corner.col(1));
20 
21  for (int c1 = 0; c1 < 3; c1++) {
22  axes.col(c1).normalize();
23  origin[c1] = corner.col(origin_vert[c1]).dot(axes.col(c1));
24  double dot_prod =
25  corner.col(opposite_vert[c1]).dot(axes.col(c1)) - origin[c1];
26  if (fabs(dot_prod) < 1e-10) // projection is too small, invalid triangle
27  {
28  bValid = false;
29  return;
30  }
31 
32  axes.col(c1) /= dot_prod;
33  }
34 
35  origin[0] = corner.col(0).dot(axes.col(0));
36  origin[1] = corner.col(0).dot(axes.col(1));
37  origin[2] = corner.col(1).dot(axes.col(2));
38 
39  bValid = true;
40  }
41 
42  inline Eigen::Vector2d normal_vector(const Eigen::Vector2d& v) {
43  return Eigen::Vector2d(v(1), -v(0));
44  };
45 
46  Eigen::Matrix<double, 2, 3> corner;
47 
48  Eigen::Matrix<double, 2, 3> axes;
49 
50  double origin[3];
51 
52  bool bValid;
53 
54  static int opposite_vert[3];
55 
56  static int origin_vert[3];
57 };
58 } // namespace detail
59 } // namespace collision
Eigen::Vector2d v2() const
Definition: triangle.cc:76
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Triangle_SAT2D(const Triangle &tri)
Triangle.
Definition: triangle.h:17
Eigen::Vector2d v1() const
Definition: triangle.cc:74
Eigen::Vector2d v3() const
Definition: triangle.cc:78
Eigen::Matrix< double, 2, 3 > corner
Eigen::Matrix< double, 2, 3 > axes
Eigen::Vector2d normal_vector(const Eigen::Vector2d &v)