Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
rotate_vector_2d.hpp
Go to the documentation of this file.
1#ifndef FANG_ROBOTICS_MCB_UTIL_MATH_GEOMETRY_ROTATE_VECTOR_2D
2#define FANG_ROBOTICS_MCB_UTIL_MATH_GEOMETRY_ROTATE_VECTOR_2D
5
6namespace fang::math
7{
12 template<typename Unit>
13 Vector2D<Unit> rotateVector2D(const Vector2D<Unit>& vector, const Radians& rotationAngle)
14 {
15 //Rotation matrix
16 //https://www.youtube.com/watch?v=1oYEo7PNIBQ
17 //I know it's Wikipedia but it's will help wwith the youtube video
18 //In general, Wikipedia is pretty good as a math reference, too.
19 //https://en.wikipedia.org/wiki/Rotation_matrix
20
21 const double angle{rotationAngle.to<double>()};
22 const double rotatedx{vector.x * (std::cos(angle)) - vector.y * (std::sin(angle))};
23 const double rotatedy{vector.x * (std::sin(angle)) + vector.y * (std::cos(angle))};
24
25 return Vector2D<Unit>{Unit{rotatedx}, Unit{rotatedy}};
26 }
27}
28#endif
Definition range.hpp:4
Vector2D< Unit > rotateVector2D(const Vector2D< Unit > &vector, const Radians &rotationAngle)
Definition rotate_vector_2d.hpp:13
Definition vector_2d.hpp:8
Unit x
Definition vector_2d.hpp:11
Unit y
Definition vector_2d.hpp:12
units::angle::radian_t Radians
Definition units_alias.hpp:16