Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
angle_and_norms.cpp
Go to the documentation of this file.
2
3#include <iostream>
6 double norm1 = std::sqrt(vector1.x * vector1.x + vector1.y * vector1.y);
7 double norm2 = std::sqrt(vector2.x * vector2.x + vector2.y * vector2.y);
8 double dot_product = vector1.x * vector2.x + vector1.y * vector2.y;
9 double cossine = dot_product / (norm1 * norm2);
10 double angle;
11 if (std::fabs(cossine - 1.0) < 1e-3) {
12 angle = 0.0;
13 } else if (std::fabs(cossine + 1.0) < 1e-3) {
14 angle = -M_PI;
15 } else {
16 angle = std::acos(cossine);
17 }
18 return common_lib::maths::AngleAndNorms(angle, norm1, norm2);
19}
20
AngleAndNorms angle_and_norms(const TwoDVector &vector1, const TwoDVector &vector2)
Function used to calculate the angle between two vectors and their norms.
structure to store the angle formed between two vectors and their norms