Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "utils.h"
  2. LFRPoint::LFRPoint(/* args */) : x(0.0), y(0.0)
  3. {
  4. }
  5. LFRPoint::LFRPoint(double x, double y): x(x), y(y)
  6. {
  7. }
  8. LFRPoint::~LFRPoint()
  9. {
  10. }
  11. LFRVector::LFRVector(/* args */) : LFRPoint()
  12. {
  13. }
  14. LFRVector::LFRVector(double x, double y) : LFRPoint(x, y)
  15. {
  16. }
  17. LFRVector::LFRVector(const LFRPoint& pt) : LFRPoint(pt)
  18. {
  19. }
  20. LFRVector::~LFRVector()
  21. {
  22. }
  23. double LFRVector::angle(const LFRVector& other) const
  24. {
  25. return acos(dot(other)/(this->norm()*other.norm())) * (180.0/M_PI);
  26. }
  27. double LFRVector::dot(const LFRVector& other) const
  28. {
  29. return x*other.x + y*other.y;
  30. }
  31. double LFRVector::norm() const
  32. {
  33. return sqrt(x*x+y*y);
  34. }
  35. LFRLine::LFRLine(/* args */) : start(), dir()
  36. {
  37. }
  38. LFRLine::LFRLine(LFRPoint start, LFRVector dir) : start(start), dir(dir)
  39. {
  40. }
  41. LFRLine::LFRLine(LFRPoint start, LFRPoint end) : start(start)
  42. {
  43. dir = end - start;
  44. }
  45. LFRLine::~LFRLine()
  46. {
  47. }
  48. int Calcs::calcAngle(int deltaX, int deltaY){
  49. int refAngle = 0;
  50. if(deltaX > 10E-12){
  51. refAngle = (int)((atan(deltaY/deltaX) * 180.0/M_PI) + 0.5 - (refAngle<0)); //Here 0.5 (or -0.5) is added to round a float number to int right
  52. // convert from img coordinates to regbot coordinates
  53. refAngle = -(refAngle);
  54. if (refAngle > 90)
  55. refAngle = refAngle - 180;
  56. }else{
  57. refAngle = -90;
  58. }
  59. return refAngle;
  60. }