MatrixOperations.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /// \file MatrixOperations.h
  2. /// \brief Simple matrix operations
  3. /// \author Hatem Darweesh
  4. /// \date Jun 19, 2016
  5. #ifndef MATRIXOPERATIONS_H_
  6. #define MATRIXOPERATIONS_H_
  7. #include "RoadNetwork.h"
  8. #include <math.h>
  9. namespace PlannerHNS {
  10. class Mat3
  11. {
  12. double m[3][3];
  13. public:
  14. Mat3()
  15. {
  16. //initialize Identity by default
  17. for(int i=0;i<3;i++)
  18. for(int j=0;j<3;j++)
  19. m[i][j] = 0;
  20. m[0][0] = m[1][1] = m[2][2] = 1;
  21. }
  22. Mat3(double transX, double transY, bool mirrorX, bool mirrorY )
  23. {
  24. m[0][0] = (mirrorX == true ) ? -1 : 1; m[0][1] = 0; m[0][2] = transX;
  25. m[1][0] = 0; m[1][1] = (mirrorY==true) ? -1 : 1; m[1][2] = transY;
  26. m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  27. }
  28. Mat3(double transX, double transY)
  29. {
  30. m[0][0] = 1; m[0][1] = 0; m[0][2] = transX;
  31. m[1][0] = 0; m[1][1] = 1; m[1][2] = transY;
  32. m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  33. }
  34. Mat3(double rotation_angle)
  35. {
  36. double c = cos(rotation_angle);
  37. double s = sin(rotation_angle);
  38. m[0][0] = c; m[0][1] = -s; m[0][2] = 0;
  39. m[1][0] = s; m[1][1] = c; m[1][2] = 0;
  40. m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  41. }
  42. Mat3(GPSPoint rotationCenter)
  43. {
  44. double c = cos(rotationCenter.a);
  45. double s = sin(rotationCenter.a);
  46. double u = rotationCenter.x;
  47. double v = rotationCenter.y;
  48. m[0][0] = c; m[0][1] = -s; m[0][2] = -u*c + v*s + u;
  49. m[1][0] = s; m[1][1] = c; m[1][2] = -u*s - v*c + v;
  50. m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  51. }
  52. GPSPoint operator * (GPSPoint v)
  53. {
  54. GPSPoint _v = v;
  55. v.x = m[0][0]*_v.x + m[0][1]*_v.y + m[0][2]*1;
  56. v.y = m[1][0]*_v.x + m[1][1]*_v.y + m[1][2]*1;
  57. return v;
  58. }
  59. };
  60. } /* namespace PlannerHNS */
  61. #endif /* MATRIXOPERATIONS_H_ */