8#ifndef HOLISTIC_FUSION_MATH_UTILS_H
9#define HOLISTIC_FUSION_MATH_UTILS_H
22 return radians * 180.0 / M_PI;
31 return (
float)(radians * 180.0 / M_PI);
40 return degrees * M_PI / 180.0;
49 return (
float)(degrees * M_PI / 180.0);
58template <
typename Po
intT>
60 float diffX = a.x - b.x;
61 float diffY = a.y - b.y;
62 float diffZ = a.z - b.z;
64 return diffX * diffX + diffY * diffY + diffZ * diffZ;
74template <
typename Po
intT>
76 float diffX = a.x - b.x * wb;
77 float diffY = a.y - b.y * wb;
78 float diffZ = a.z - b.z * wb;
80 return diffX * diffX + diffY * diffY + diffZ * diffZ;
88template <
typename Po
intT>
90 return std::sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
98template <
typename Po
intT>
100 return p.x * p.x + p.y * p.y + p.z * p.z;
108template <
typename Po
intT>
111 p.y = ang.
cos() * y - ang.
sin() * p.z;
112 p.z = ang.
sin() * y + ang.
cos() * p.z;
120template <
typename Po
intT>
123 p.x = ang.
cos() * x + ang.
sin() * p.z;
124 p.z = ang.
cos() * p.z - ang.
sin() * x;
132template <
typename Po
intT>
135 p.x = ang.
cos() * x - ang.
sin() * p.y;
136 p.y = ang.
sin() * x + ang.
cos() * p.y;
146template <
typename Po
intT>
160template <
typename Po
intT>
173 m_out = Eigen::Matrix4d::Identity();
174 Eigen::Matrix3d R = m_in.block<3, 3>(0, 0);
175 Eigen::Vector3d t = m_in.block<3, 1>(0, 3);
176 m_out.block<3, 3>(0, 0) = R.transpose();
177 m_out.block<3, 1>(0, 3) = -R.transpose() * t;
Class for holding an angle.
float calcPointDistance(const PointT &p)
Calculate the absolute distance of the point to the origin.
void rotX(PointT &p, const Angle &ang)
Rotate the given point by the specified angle around the x-axis.
double deg2rad(double degrees)
Convert the given degree angle to radian.
double rad2deg(double radians)
Convert the given radian angle to degrees.
float calcSquaredPointDistance(const PointT &p)
Calculate the squared distance of the point to the origin.
float calcSquaredDiff(const PointT &a, const PointT &b)
Calculate the squared difference of the given two points.
void invertHomogenousMatrix(const Eigen::Matrix4d &m_in, Eigen::Matrix4d &m_out)
Invert a homogenous transformation matrix.
void rotateZXY(PointT &p, const Angle &angZ, const Angle &angX, const Angle &angY)
Rotate the given point by the specified angles around the z-, x- respectively y-axis.
void rotY(PointT &p, const Angle &ang)
Rotate the given point by the specified angle around the y-axis.
void rotZ(PointT &p, const Angle &ang)
Rotate the given point by the specified angle around the z-axis.
void rotateYXZ(PointT &p, const Angle &angY, const Angle &angX, const Angle &angZ)
Rotate the given point by the specified angles around the y-, x- respectively z-axis.