The following functions can be used to retrieve the direction of a given vector.
-
constexpr double direction_radiants_y() const;
-
constexpr double direction_radiants_x() const;
-
constexpr double direction_degrees_y() const;
-
constexpr double direction_degrees_x() const
-
constexpr double direction_cosine(Cos type) const;
-
constexpr double direction_angle(Cos type) const;
- Calculates the direction of a 2D vector (in radiants) in respect to the y axis.
- Same as 1), but the direction is in respect to the x axis.
- Calculates the direction of a 2D vector in degrees, in respect to the y axis.
- Same as 3), but the direction is in respect to the x axis.
- Calculates the direction cosine of a 3D vector in respect to a given axis
type
, which includes:MathLbr::Cos::X_AXIS
,MathLbr::Cos::Y_AXIS
,MathLbr::Cos::Z_AXIS
. - Same as 5, but returns performs
std::acos
on the result of 5).
In all the cases, these functions only work for non-std::complex
types. An assert is performed for each function to check whether the sizes are correct. If asserts are disabled, then the functions will proceed with the calculations resulting in undefined behavior.
#include "vector.h"
#include <iostream>
int main() {
MathLbr::vector<int> a{ {2,3} };
MathLbr::vector<double> b{ {5.5, 3.4, 2.0} };
std::cout << a.direction_degrees_x();
a.direction_radiants_y();
b.direction_cosine(MathLbr::Cos::Y_AXIS);
// same as:
b.direction_cosine(MathLbr::Y_AXIS);
}