34#include <NDEVR/Angle.h>
35#include <NDEVR/Vector.h>
43 template<
class t_type_a,
class t_type_b>
46 return angle_a.template internal<false>() >
cast<t_type_a>(angle_b.template internal<false>());
52 template<
class t_type_a,
class t_type_b>
55 return angle_a.template internal<false>() <
cast<t_type_a>(angle_b.template internal<false>());
61 template<
class t_type_a,
class t_type_b>
64 return angle_a.template internal<false>() >=
cast<t_type_a>(angle_b.template internal<false>());
70 template<
class t_type_a,
class t_type_b>
73 return angle_a.template internal<false>() <=
cast<t_type_a>(angle_b.template internal<false>());
78 template<
class t_type>
103 template<
class t_type>
106 return ::sin(angle.template as<RADIANS>());
113 template<
class t_type>
114 t_type
sin(
const t_type& angle)
123 template<
class t_type>
127 return sin(internal_angle);
134 template<
class t_type>
137 return ::cos(angle.template as<RADIANS>());
144 template<
class t_type>
145 t_type
cos(
const t_type& angle)
155 template<
class t_type>
158 return sin(angle) /
cos(angle);
165 template<
class t_type>
168 return ::tan(angle.template as<RADIANS>());
176 template<
class t_type>
177 t_type
tan(
const t_type& angle)
188 template<
class t_type>
199 template<
class t_type>
211 template<
class t_type>
227 template<u
int01 t_dims,
class t_type>
231 for (
uint01 dim = 0; dim < t_dims; ++dim)
233 angle[dim] =
difference(angle_a[dim], angle_b[dim]);
245 template<
class t_type>
260 template<u
int01 t_dims,
class t_type>
264 for (
uint01 dim = 0; dim < t_dims; ++dim)
266 angle[dim] =
Average(angle_a[dim], angle_b[dim]);
277 template<
class t_type>
289 template<
class t_type>
301 template<
class t_type,
class t_angle_type>
313 template<
class t_type,
class t_angle_type>
324 template<
class t_type,
class t_vector_type>
325 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>
::type
326 operator*(
const t_vector_type& angle,
const t_type& mult)
328 t_vector_type product;
329 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
330 product[dim] = angle[dim] * mult;
340 template<
class t_type,
class t_vector_type>
341 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>
::type
342 operator*(
const t_vector_type& angle,
const t_type& mult)
344 t_vector_type product;
345 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
346 product[dim] = angle[dim] * mult;
356 template<u
int01 t_dims,
class t_type,
class t_vector_type>
357 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<fltp08>>, t_vector_type>::value, t_vector_type>
::type
360 t_vector_type product;
361 for (
uint01 dim = 0; dim < t_dims; ++dim)
362 product[dim] = angle[dim] * mult[dim];
372 template<u
int01 t_dims,
class t_type,
class t_vector_type>
373 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<sint04>>, t_vector_type>::value, t_vector_type>
::type
376 t_vector_type product;
377 for (
uint01 dim = 0; dim < t_dims; ++dim)
378 product[dim] = angle[dim] * mult[dim];
388 template<
class t_type,
class t_vector_type>
389 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>
::type
390 operator*(
const t_type& mult,
const t_vector_type& angle)
392 t_vector_type product;
393 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
394 product[dim] = mult * angle[dim];
403 template<
class t_type,
class t_vector_type>
404 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>
::type
405 operator*(
const t_type& mult,
const t_vector_type& angle)
407 t_vector_type product;
408 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
409 product[dim] = mult * angle[dim];
418 template<u
int01 t_dims,
class t_type,
class t_vector_type>
419 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<fltp08>>, t_vector_type>::value, t_vector_type>
::type
422 t_vector_type product;
423 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
424 product[dim] = mult[dim] * angle[dim];
433 template<u
int01 t_dims,
class t_type,
class t_vector_type>
434 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<sint04>>, t_vector_type>::value, t_vector_type>
::type
437 t_vector_type product;
438 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
439 product[dim] = mult[dim] * angle[dim];
448 template<
class t_type,
class t_vector_type>
449 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>
::type
450 operator*(
const t_vector_type& mult,
const t_vector_type& angle)
452 t_vector_type product;
453 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
454 product[dim] = mult[dim] * angle[dim];
463 template<
class t_type,
class t_vector_type>
464 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>
::type
465 operator*(
const t_vector_type& mult,
const t_vector_type& angle)
467 t_vector_type product;
468 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
469 product[dim] = mult[dim] * angle[dim];
478 template<
class t_type,
class t_angle_type>
490 template<
class t_type,
class t_vector_type,
class t_angle_type>
491 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<t_angle_type>>::value, t_vector_type>
::type
492 operator/(
const t_vector_type& angle,
const t_type& den)
495 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
496 div[dim] = angle[dim] / den;
506 template<
class t_type,
class t_vector_type>
507 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>
::type
508 operator/(
const t_vector_type& angle,
const t_type& den)
511 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
512 div[dim] = angle[dim] / den;
522 template<
class t_type,
class t_vector_type>
523 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>
::type
524 operator/(
const t_vector_type& angle,
const t_type& den)
527 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
528 div[dim] = angle[dim] / den;
538 template<u
int01 t_dims,
class t_type,
class t_vector_type,
class t_angle_type>
539 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<t_angle_type>>, t_vector_type>::value, t_vector_type>
::type
543 for (
uint01 dim = 0; dim < t_dims; ++dim)
544 div[dim] = angle[dim] / den[dim];
554 template<u
int01 t_dims,
class t_vector_type,
class t_angle_type>
555 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<t_angle_type>>, t_vector_type>::value, Vector<t_dims, fltp08>>
::type
559 for (
uint01 dim = 0; dim < t_dims; ++dim)
560 div[dim] = angle[dim] / den[dim];
569 template<u
int01 t_dims,
class t_angle_type>
573 for (
uint01 dim = 0; dim < t_dims; ++dim)
574 div[dim] = angle[dim] / den[dim];
584 template<
class t_type,
class t_angle_type>
595 template<
class t_type,
class t_vector_type,
class t_angle_type>
596 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<t_angle_type>>::value, t_vector_type>
::type
600 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
601 div[dim] = num / angle[dim];
610 template<
class t_angle_type>
622 template<
class t_angle_type>
634 template<
class t_type,
class t_angle_type>
637 angle = angle * mult;
646 template<u
int01 t_dims,
class t_type,
class t_angle_type>
649 for (
uint01 dim = 0; dim < t_dims; ++dim)
650 angle[dim] = angle[dim] * mult;
659 template<u
int01 t_dims,
class t_type,
class t_angle_type>
662 for (
uint01 dim = 0; dim < t_dims; ++dim)
663 angle[dim] = angle[dim] * mult[dim];
672 template<
class t_angle_type>
675 angle = angle * mult;
685 template<
class t_type,
class t_angle_type>
688 angle = angle / mult;
697 template<u
int01 t_dims,
class t_type,
class t_angle_type>
700 for (
uint01 dim = 0; dim < t_dims; ++dim)
701 angle[dim] = angle[dim] / den;
710 template<u
int01 t_dims,
class t_type,
class t_angle_type>
713 for (
uint01 dim = 0; dim < t_dims; ++dim)
714 angle[dim] = angle[dim] / den[dim];
724 template<u
int01 t_dims,
class t_angle_type>
728 for (
uint01 dim = 0; dim < t_dims; ++dim)
738 template<u
int01 t_dims,
class t_angle_type>
742 for (
uint01 dim = 0; dim < t_dims; ++dim)
752 template<
class t_angle_type>
764 template<
class t_new_type, u
int01 t_dims,
class t_angle_type>
768 for(
uint01 dim = 0; dim < t_dims; ++dim)
769 angle[dim] = old[dim].
template toTypeAngle<t_new_type>();
808 template<
class t_angle_type, u
int01 t_dims,
class t_type>
828 template<
class t_angle_type>
839 template<
class t_angle_type, u
int01 t_dims,
class t_type>
851 template<
class t_angle_type, u
int01 t_dims,
class t_type>
862 template<
class t_angle_type, u
int01 t_dims,
class t_type>
865 t_type dot_product =
dot(a, b);
866 t_type length = a.template magnitude<t_type>() * b.template magnitude<t_type>();
877 template<
class t_angle_type, u
int01 t_dims,
class t_type>
881 for (
uint01 i = 0; i < t_dims; i++)
883 return orient_vector;
891 template<
bool t_normalized, u
int01 t_dims,
class t_angle_type>
895 for (
uint01 i = 0; i < t_dims; i++)
896 orient_vector[i] = ray[i].as(angle_type);
897 return orient_vector;
913 template<
class t_angle_type,
class t_type>
918 if (::fabs(
cos(pitch)) < 0.001)
920 else if (::fabs(
cos(yaw)) < 0.01)
935 template<
class t_angle_type>
938 fltp08 suggested_pitch_value = angle[
PITCH].template as<DEGREES>();
939 fltp08 our_pitch_value = reference[
PITCH].template as<DEGREES>();
941 fltp08 suggested_yaw_value = angle[
YAW].template as<DEGREES>();
942 fltp08 our_yaw_value = reference[
YAW].template as<DEGREES>();
944 fltp08 suggested_roll_value = angle[
ROLL].template as<DEGREES>();
945 fltp08 our_roll_value = reference[
ROLL].template as<DEGREES>();
947 if (suggested_pitch_value - our_pitch_value > 180)
948 our_pitch_value += 360;
949 else if (our_pitch_value - suggested_pitch_value > 180)
950 suggested_pitch_value += 360;
952 if (suggested_yaw_value - our_yaw_value > 180)
953 our_yaw_value += 360;
954 else if (our_yaw_value - suggested_yaw_value > 180)
955 suggested_yaw_value += 360;
957 if (suggested_roll_value - our_roll_value > 180)
958 our_roll_value += 360;
959 else if (our_roll_value - suggested_roll_value > 180)
960 suggested_roll_value += 360;
962 bool flip = std::abs(suggested_roll_value - our_roll_value) >= 90.0 && std::abs(suggested_yaw_value - our_yaw_value) >= 90.0;
990 template<u
int01 t_dims,
class t_angle_type>
1002 template<u
int01 t_dims,
class t_angle_type>
Logic for converting between Euler angles and basic rotations or normals.
static constexpr Vector< t_dims, Angle< t_angle_type > > Orientation(AngleType angle_type, const Vector< t_dims, t_type > &ray)
Constructs a Vector of Angles from a Vector of scalar values and a specified angle type.
static constexpr Angle< t_angle_type > AngleBetween(const Vector< t_dims, t_type > &a, const Vector< t_dims, t_type > &b)
Computes the angle between two vectors.
static constexpr Angle< t_angle_type > Inclination(const Vector< t_dims, t_type > ray)
Computes the inclination angle from a direction vector.
static constexpr Vector< t_dims, fltp08 > Orientation(AngleType angle_type, const Vector< t_dims, Angle< t_angle_type > > &ray)
Converts a Vector of Angles to a Vector of scalar values in the specified angle type.
static Vector< 3, Angle< t_angle_type > > NormalToOrientation(const Vector< 3, t_type > &normal, const Angle< t_angle_type > &yaw=Angle< t_angle_type >(0))
Normal to orientation.
static Angle< t_angle_type > Inclination(const Angle< t_angle_type > &roll, const Angle< t_angle_type > &pitch)
static Vector< 3, Angle< fltp08 > > QuaternionToOrientation(const Vector< 4, fltp08 > &quaternion)
Converts a quaternion to Euler angles (Roll, Pitch and Yaw).
static Angle< t_angle_type > Rotation(const Vector< t_dims, t_type > &left, const Vector< t_dims, t_type > &middle, const Vector< t_dims, t_type > &right)
Gets a rotation.
static constexpr Angle< t_angle_type > Heading(const Vector< t_dims, t_type > ray)
Computes the heading angle from a direction vector.
static Vector< 3, Angle< t_angle_type > > NormalizeOrientation(Vector< 3, Angle< t_angle_type > > angle, const Vector< 3, Angle< t_angle_type > > &reference)
Normalizes an orientation to be consistent with a reference orientation, avoiding discontinuities.
static const fltp08 * CalcIndexSin()
static Vector< 4, fltp08 > OrientationToQuaternion(const Vector< 3, Angle< fltp08 > > &quaternion)
Converts Euler angles (Roll, Pitch and Yaw) to a quaternion.
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
static Angle atan(t_value_type value)
Computes the principal value of the arc tangent of the given value.
static Angle acos(t_value_type value)
Computes the principal value of the arc cosine of the given value.
static Angle atan2(t_value_type x, t_value_type y)
measures the counterclockwise angle between the positive x-axis and the point (x, y)
static constexpr sint04 INDEX_PI
Optimized angle constant representing PI; allows integers to store angles to some degree of accuracy.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
constexpr t_type magnitudeSquared() const
Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
The primary namespace for the NDEVR SDK.
static constexpr Angle< t_angle_type > & operator-=(Angle< t_angle_type > &angle, const Angle< t_angle_type > &sub)
Subtraction assignment operator for Angles.
@ YAW
Rotation about the vertical axis (Z).
@ PITCH
Rotation about the lateral axis (Y).
@ ROLL
Rotation about the forward axis (X).
@ type
The type identifier string for this model node.
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
static constexpr bool operator<=(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Less-than-or-equal comparison operator.
constexpr Vector< t_dims, Angle< t_angle_type > > quantize(const Vector< t_dims, Angle< t_angle_type > > &value, Angle< t_angle_type > d=Angle< t_angle_type >(DEGREES, 1.0))
Quantizes a Vector of Angles to the nearest multiple of a given step size.
double fltp08
Defines an alias representing an 8 byte floating-point number.
static constexpr Angle< t_type > Average(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Calculates the average of two normalized angles.
AngleType
The possible units that can be used by the angle class.
@ DEGREES
Angle measured in degrees (0 to 360 for a full circle).
@ INTERNAL_ANGLE
The angle internally used by the angle class.
@ RADIANS
Angle measured in radians (0 to 2*PI for a full circle).
static constexpr bool operator>=(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Greater-than-or-equal comparison operator.
static constexpr Angle< t_type > operator*(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Multiplication operator.
static constexpr Angle< t_type > operator-(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Subtraction operator.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr Angle< t_angle_type > & operator+=(Angle< t_angle_type > &angle, const Angle< t_angle_type > &add)
Addition assignment operator for Angles.
static constexpr Angle< t_angle_type > & operator/=(Angle< t_angle_type > &angle, const t_type &mult)
Division assignment operator for an Angle and a scalar.
static constexpr bool operator<(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Less-than comparison operator.
static constexpr Angle< t_type > difference(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Calculates minimal absolute signed angle between two angles.
static constexpr Angle< t_angle_type > & operator*=(Angle< t_angle_type > &angle, const t_type &mult)
Multiplication assignment operator for an Angle and a scalar.
static constexpr Angle< t_type > operator+(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Addition operator.
const fltp08 *const s_index_sin
Pre-computed sine lookup table for optimized trigonometric operations.
t_type sqrt(const t_type &value)
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type sin(const Angle< t_type > &angle)
Performs optimized sine operation on the given angle using pre-computed lookup table for optimal spee...
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type tan(const Angle< t_type > &angle)
Performs optimized tangent operation on the given angle using pre-computed lookup table for optimal s...
static constexpr fltp08 operator/(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Division operator.
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type cos(const Angle< t_type > &angle)
Performs optimized cosine operation on the given angle using pre-computed lookup table for optimal sp...
constexpr Vector< t_dims, Angle< t_angle_type > > operator%(const Vector< t_dims, Angle< t_angle_type > > &vec_a, const Vector< t_dims, Angle< t_angle_type > > &vec_b)
Element-wise modulo operator for two Vectors of Angles.
constexpr t_type clip(const t_type &value, const t_type &lower_bound, const t_type &upper_bound)
Clips the value given so that that the returned value falls between upper and lower bound.
static constexpr bool operator>(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Greater-than comparison operator.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
constexpr Vector< t_dims, Angle< t_new_type > > ToTypeAngle(const Vector< t_dims, Angle< t_angle_type > > &old)
Converts a Vector of one angle to a different container type.