25 namespace perception {
32 template <
typename Type>
34 const Eigen::Matrix<Type, 2, 1> &point2,
35 const Eigen::Matrix<Type, 2, 1> &point3) {
36 return (point2.x() - point1.x()) * (point3.y() - point1.y()) -
37 (point3.x() - point1.x()) * (point2.y() - point1.y());
44 template <
typename Po
intT>
47 const PointT &point3) {
48 return (point2.x - point1.x) * (point3.y - point1.y) -
49 (point3.x - point1.x) * (point2.y - point1.y);
54 template <
typename Po
intT>
57 typename PointT::Type dist = (pt1.x - pt2.x) * (pt1.x - pt2.x);
58 dist += (pt1.y - pt2.y) * (pt1.y - pt2.y);
59 dist += (pt1.z - pt2.z) * (pt1.z - pt2.z);
60 return static_cast<typename PointT::Type
>(sqrt(dist));
65 template <
typename Po
intT>
68 typename PointT::Type dist = (pt1.x - pt2.x) * (pt1.x - pt2.x);
69 dist += (pt1.y - pt2.y) * (pt1.y - pt2.y);
70 return static_cast<typename PointT::Type
>(sqrt(dist));
78 const Eigen::Matrix<T, 3, 1> &v2) {
79 T v1_len =
static_cast<T
>(sqrt((v1.head(2).cwiseProduct(v1.head(2))).sum()));
80 T v2_len =
static_cast<T
>(sqrt((v2.head(2).cwiseProduct(v2.head(2))).sum()));
81 if (v1_len < std::numeric_limits<T>::epsilon() ||
82 v2_len < std::numeric_limits<T>::epsilon()) {
85 T cos_theta = (v1.head(2).cwiseProduct(v2.head(2))).sum() / (v1_len * v2_len);
93 const Eigen::Matrix<T, 3, 1> &v2) {
94 T v1_len =
static_cast<T
>(sqrt((v1.head(2).cwiseProduct(v1.head(2))).sum()));
95 T v2_len =
static_cast<T
>(sqrt((v2.head(2).cwiseProduct(v2.head(2))).sum()));
96 if (v1_len < std::numeric_limits<T>::epsilon() ||
97 v2_len < std::numeric_limits<T>::epsilon()) {
101 (v1.head(2).cwiseProduct(v2.head(2))).sum() / (v1_len * v2_len);
102 const T sin_theta = (v1(0) * v2(1) - v1(1) * v2(0)) / (v1_len * v2_len);
103 T theta = std::acos(cos_theta);
104 if (sin_theta < 0.0) {
113 template <
typename T>
115 const Eigen::Matrix<T, 3, 1> &v1,
const Eigen::Matrix<T, 3, 1> &v2) {
116 T v1_len =
static_cast<T
>(sqrt((v1.head(2).cwiseProduct(v1.head(2))).sum()));
117 T v2_len =
static_cast<T
>(sqrt((v2.head(2).cwiseProduct(v2.head(2))).sum()));
118 if (v1_len < std::numeric_limits<T>::epsilon() ||
119 v2_len < std::numeric_limits<T>::epsilon()) {
120 return Eigen::Matrix<T, 3, 3>::Zero(3, 3);
124 (v1.head(2).cwiseProduct(v2.head(2))).sum() / (v1_len * v2_len);
125 const T sin_theta = (v1(0) * v2(1) - v1(1) * v2(0)) / (v1_len * v2_len);
127 Eigen::Matrix<T, 3, 3> rot_mat;
128 rot_mat << cos_theta, sin_theta, 0, -sin_theta, cos_theta, 0, 0, 0, 1;
134 template <
typename T>
136 const Eigen::Matrix<T, 3, 1> &projected_vector,
137 const Eigen::Matrix<T, 3, 1> &project_vector) {
138 if (projected_vector.head(2).norm() < std::numeric_limits<T>::epsilon() ||
139 project_vector.head(2).norm() < std::numeric_limits<T>::epsilon()) {
140 return Eigen::Matrix<T, 3, 1>::Zero(3, 1);
142 Eigen::Matrix<T, 3, 1> project_dir = project_vector;
143 project_dir(2) = 0.0;
144 project_dir.normalize();
146 const T projected_vector_project_dir_inner_product =
147 projected_vector(0) * project_dir(0) +
148 projected_vector(1) * project_dir(1);
149 const T projected_vector_project_dir_angle_cos =
150 projected_vector_project_dir_inner_product /
151 (projected_vector.head(2).norm() * project_dir.head(2).norm());
152 const T projected_vector_norm_on_project_dir =
153 projected_vector.head(2).norm() * projected_vector_project_dir_angle_cos;
154 return project_dir * projected_vector_norm_on_project_dir;
159 template <
typename Po
intT>
161 typename PointT::Type *h_angle_in_degree,
162 typename PointT::Type *v_angle_in_degree,
163 typename PointT::Type *dist) {
164 using T =
typename PointT::Type;
165 const T radian_to_degree = 180.0 / M_PI;
170 (*dist) =
static_cast<T
>(sqrt(x * x + y * y + z * z));
171 T dist_xy =
static_cast<T
>(sqrt(x * x + y * y));
173 (*h_angle_in_degree) = std::acos(x / dist_xy) * radian_to_degree;
175 (*h_angle_in_degree) =
static_cast<T
>(360.0) - (*h_angle_in_degree);
178 (*v_angle_in_degree) = std::acos(dist_xy / (*dist)) * radian_to_degree;
180 (*v_angle_in_degree) = -(*v_angle_in_degree);
Eigen::Matrix< T, 3, 3 > CalculateRotationMat2DXY(const Eigen::Matrix< T, 3, 1 > &v1, const Eigen::Matrix< T, 3, 1 > &v2)
Definition: basic.h:114
T CalculateTheta2DXY(const Eigen::Matrix< T, 3, 1 > &v1, const Eigen::Matrix< T, 3, 1 > &v2)
Definition: basic.h:92
Eigen::Matrix< T, 3, 1 > Calculate2DXYProjectVector(const Eigen::Matrix< T, 3, 1 > &projected_vector, const Eigen::Matrix< T, 3, 1 > &project_vector)
Definition: basic.h:135
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Type CrossProduct(const Eigen::Matrix< Type, 2, 1 > &point1, const Eigen::Matrix< Type, 2, 1 > &point2, const Eigen::Matrix< Type, 2, 1 > &point3)
Definition: basic.h:33
void ConvertCartesiantoPolarCoordinate(const PointT &xyz, typename PointT::Type *h_angle_in_degree, typename PointT::Type *v_angle_in_degree, typename PointT::Type *dist)
Definition: basic.h:160
T CalculateCosTheta2DXY(const Eigen::Matrix< T, 3, 1 > &v1, const Eigen::Matrix< T, 3, 1 > &v2)
Definition: basic.h:77
PointT::Type CalculateEuclidenDist2DXY(const PointT &pt1, const PointT &pt2)
Definition: basic.h:66
PointT::Type CalculateEuclidenDist(const PointT &pt1, const PointT &pt2)
Definition: basic.h:55