pose2d.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Created by zx on 22-12-1.
  3. //
  4. #ifndef LIO_LIVOX_CPP_MPC_POSE2D_H_
  5. #define LIO_LIVOX_CPP_MPC_POSE2D_H_
  6. #include <iostream>
  7. #include <atomic>
  8. /*
  9. * 带direction的二维点,与x轴正方向逆时针为正方向
  10. */
  11. class Pose2d
  12. {
  13. public:
  14. Pose2d();
  15. Pose2d(float x,float y,float theta);
  16. Pose2d(const Pose2d& point)
  17. {
  18. m_x=point.x();
  19. m_y=point.y();
  20. m_theta=point.theta();
  21. }
  22. ~Pose2d();
  23. Pose2d& operator=(const Pose2d& point)
  24. {
  25. m_x=point.x();
  26. m_y=point.y();
  27. m_theta=point.theta();
  28. return *this;
  29. }
  30. Pose2d operator-(const Pose2d& pose)const
  31. {
  32. float x=m_x-pose.x();
  33. float y=m_y-pose.y();
  34. float theta=m_theta-pose.theta();
  35. return Pose2d(x,y,theta);
  36. }
  37. Pose2d operator+(const Pose2d& pose)const
  38. {
  39. float x=m_x+pose.x();
  40. float y=m_y+pose.y();
  41. float theta=m_theta+pose.theta();
  42. return Pose2d(x,y,theta);
  43. }
  44. static Pose2d abs(const Pose2d& pose)
  45. {
  46. Pose2d ret(std::abs(pose.x()),std::abs(pose.y()),std::abs(pose.theta()));
  47. return ret;
  48. }
  49. bool operator<(const Pose2d& pose)const
  50. {
  51. return x()<pose.x()&&y()<pose.y()&&theta()<pose.theta();
  52. }
  53. /*
  54. * 将点顺时针旋转theta
  55. */
  56. Pose2d rotate(float theta)const;
  57. friend std::ostream& operator<<(std::ostream &out,const Pose2d& point);
  58. const float x() const {return m_x;};
  59. const float y() const {return m_y;};
  60. const float theta() const {return m_theta;}
  61. const float gridient()const;
  62. static float distance(const Pose2d& pose1,const Pose2d& pose2);
  63. static Pose2d PoseByPose(const Pose2d& world_pose,const Pose2d& axis_pose);
  64. protected:
  65. std::atomic<float> m_x;
  66. std::atomic<float> m_y;
  67. std::atomic<float> m_theta; //梯度角,与x轴正方形逆时针为正,单位弧度
  68. };
  69. #endif //LIO_LIVOX_CPP_MPC_POSE2D_H_