Browse Source

Introduce angle calculation

master
Tim Zeuner 1 year ago
parent
commit
0aa939db39
2 changed files with 22 additions and 1 deletions
  1. 16
    0
      AutonomousMode/Utils/utils.cpp
  2. 6
    1
      AutonomousMode/Utils/utils.h

+ 16
- 0
AutonomousMode/Utils/utils.cpp View File

@@ -31,6 +31,22 @@ LFRVector::~LFRVector()
{
}

double LFRVector::angle(const LFRVector& other) const
{
return acos(dot(other)/(this->norm()*other.norm()));
}

double LFRVector::dot(const LFRVector& other) const
{
return x*other.x + y*other.y;
}

double LFRVector::norm() const
{
return sqrt(x*x+y*y);
}


LFRLine::LFRLine(/* args */) : start(), dir()
{
}

+ 6
- 1
AutonomousMode/Utils/utils.h View File

@@ -1,6 +1,7 @@
#pragma once

#include <opencv2/opencv.hpp>
#include <cmath>

using namespace cv;
using namespace std;
@@ -30,6 +31,10 @@ public:
LFRVector(const LFRPoint& pt);
~LFRVector();

double angle(const LFRVector& other) const;
double dot(const LFRVector& other) const;
double norm() const;

};

class LFRLine
@@ -60,7 +65,7 @@ public:
std::vector<cv::Rect> boundingBoxes;
std::vector<cv::Point> leftEdges;
std::vector<cv::Point> middlePoints;
int angle; //Angle of the contour the robot has to follow to
double angle; //Angle of the contour the robot has to follow to
int index; //Index of the contour the robot has to follow to

FrameData(): contours(), boundingBoxes(), leftEdges(), middlePoints() {}

Loading…
Cancel
Save