// // Created by zx on 22-12-1. // #ifndef LIO_LIVOX_CPP_MPC_POSE2D_H_ #define LIO_LIVOX_CPP_MPC_POSE2D_H_ #include #include #include /* * 带direction的二维点,与x轴正方向逆时针为正方向 */ class Pose2d { public: Pose2d(); Pose2d(float x,float y,float theta); Pose2d(const Pose2d& point) { m_x=point.x(); m_y=point.y(); m_theta=point.theta(); } ~Pose2d(); Pose2d& operator=(const Pose2d& point) { m_x=point.x(); m_y=point.y(); m_theta=point.theta(); return *this; } /* * 两位姿相减,角度在-PI ,PI */ Pose2d operator-(const Pose2d& pose)const { float x=m_x-pose.x(); float y=m_y-pose.y(); float theta=m_theta-pose.theta(); const double PI=3.14159265; if(theta<0) theta=theta+2*PI; if(theta>=2*PI) theta-=2*PI; if(theta>PI) theta=theta-2*PI; return Pose2d(x,y,theta); } Pose2d operator+(const Pose2d& pose) { float x=m_x+pose.x(); float y=m_y+pose.y(); float theta=m_theta+pose.theta(); //转换到 [-pi, pi]下 int n=int(theta/(2*M_PI)); if(theta<-M_PI) { theta += 2*M_PI*(n+1); } if(theta>M_PI) { theta -= 2*M_PI*(n+1); } return Pose2d(x,y,theta); } static Pose2d abs(const Pose2d& pose) { Pose2d ret(fabs(pose.x()),fabs(pose.y()),fabs(pose.theta())); return ret; } bool operator<(const Pose2d& pose) { return x()