NDEVR
API Documentation
AngleFunctions.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: AngleFunctions
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Angle.h>
35#include <NDEVR/Vector.h>
36namespace NDEVR
37{
38 extern NDEVR_BASE_API const fltp08* const s_index_sin;
43 template<class t_type_a, class t_type_b>
44 constexpr static bool operator>(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
45 {
46 return angle_a.template internal<false>() > cast<t_type_a>(angle_b.template internal<false>());
47 }
48
52 template<class t_type_a, class t_type_b>
53 constexpr static bool operator<(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
54 {
55 return angle_a.template internal<false>() < cast<t_type_a>(angle_b.template internal<false>());
56 }
57
61 template<class t_type_a, class t_type_b>
62 constexpr static bool operator>=(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
63 {
64 return angle_a.template internal<false>() >= cast<t_type_a>(angle_b.template internal<false>());
65 }
66
70 template<class t_type_a, class t_type_b>
71 constexpr static bool operator<=(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
72 {
73 return angle_a.template internal<false>() <= cast<t_type_a>(angle_b.template internal<false>());
74 }
75
78 template<class t_type>
79 typename std::enable_if<!ObjectInfo<t_type>::Float, fltp08>::type sin(const Angle<t_type>& angle)
80 {
81
82 const uint02 internal_angle = cast<uint02>(angle.template internal<true>());
83 if (internal_angle <= Angle<t_type>::INDEX_PI)
84 {
85 if (internal_angle > (Angle<t_type>::INDEX_PI / 2))
86 return s_index_sin[Angle<t_type>::INDEX_PI - internal_angle];
87 else
88 return s_index_sin[internal_angle];
89 }
90 else
91 {
92 if (internal_angle >= Angle<t_type>::INDEX_PI + (Angle<t_type>::INDEX_PI / 2))
93 return -s_index_sin[2 * Angle<t_type>::INDEX_PI - internal_angle];
94 else
95 return -s_index_sin[internal_angle - Angle<t_type>::INDEX_PI];
96 }
97 }
98
103 template<class t_type>
104 typename std::enable_if<ObjectInfo<t_type>::Float, fltp08>::type sin(const Angle<t_type>& angle)
105 {
106 return ::sin(angle.template as<RADIANS>());
107 }
108
113 template<class t_type>
114 t_type sin(const t_type& angle)
115 {
116 return ::sin(angle);
117 }
118
123 template<class t_type>
124 typename std::enable_if<!ObjectInfo<t_type>::Float, fltp08>::type cos(const Angle<t_type>& angle)
125 {
126 const Angle<t_type> internal_angle = Angle<t_type>(cast<uint02>((angle.template internal<true>() + (Angle<t_type>::INDEX_PI / 2)) % (2 * Angle<t_type>::INDEX_PI)));
127 return sin(internal_angle);
128 }
129
134 template<class t_type>
135 typename std::enable_if<ObjectInfo<t_type>::Float, fltp08>::type cos(const Angle<t_type>& angle)
136 {
137 return ::cos(angle.template as<RADIANS>());
138 }
139
144 template<class t_type>
145 t_type cos(const t_type& angle)
146 {
147 return ::cos(angle);
148 }
149
155 template<class t_type>
156 typename std::enable_if<!ObjectInfo<t_type>::Float, fltp08>::type tan(const Angle<t_type>& angle)
157 {
158 return sin(angle) / cos(angle);
159 }
160
165 template<class t_type>
166 typename std::enable_if<ObjectInfo<t_type>::Float, fltp08>::type tan(const Angle<t_type>& angle)
167 {
168 return ::tan(angle.template as<RADIANS>());
169 }
170
176 template<class t_type>
177 t_type tan(const t_type& angle)
178 {
179 return ::tan(angle);
180 }
181
188 template<class t_type>
189 constexpr static Angle<t_type> operator-(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
190 {
191 return Angle<t_type>(cast<t_type>(angle_a.template internal<false>() - angle_b.template internal<false>()));
192 }
193
199 template<class t_type>
200 constexpr static Angle<t_type> operator+(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
201 {
202 return Angle<t_type>(cast<t_type>(angle_a.template internal<false>() + angle_b.template internal<false>()));
203 }
204
211 template<class t_type>
212 constexpr static Angle<t_type> difference(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
213 {
214 Angle<t_type> angle = (angle_a - angle_b).normalized();
215 if (angle <= Angle<t_type>(DEGREES, 180.0f))
216 return angle;
217 else
218 return Angle<t_type>(DEGREES, -360.0f) + angle;
219 }
220
227 template<uint01 t_dims, class t_type>
228 constexpr static Vector<t_dims, Angle<t_type>> difference(const Vector<t_dims, Angle<t_type>>& angle_a, const Vector<t_dims, Angle<t_type>>& angle_b)
229 {
231 for (uint01 dim = 0; dim < t_dims; ++dim)
232 {
233 angle[dim] = difference(angle_a[dim], angle_b[dim]);
234 }
235 return angle;
236 }
237
245 template<class t_type>
246 constexpr static Angle<t_type> Average(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
247 {
248 Angle<t_type> angle = difference(angle_a, angle_b) / 2.0;
249 angle += angle_b;
250 return angle;
251 }
252
260 template<uint01 t_dims, class t_type>
261 constexpr static Vector<t_dims, Angle<t_type>> Average(const Vector<t_dims, Angle<t_type>>& angle_a, const Vector<t_dims, Angle<t_type>>& angle_b)
262 {
264 for (uint01 dim = 0; dim < t_dims; ++dim)
265 {
266 angle[dim] = Average(angle_a[dim], angle_b[dim]);
267 }
268 return angle;
269 }
270
277 template<class t_type>
278 constexpr static Angle<t_type> operator*(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
279 {
280 return Angle<t_type>(cast<t_type>(angle_a.template internal<false>() * angle_b.template internal<false>()));
281 }
282
289 template<class t_type>
290 constexpr static fltp08 operator/(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
291 {
292 return cast<fltp08>(angle_a.template internal<false>()) / cast<fltp08>(angle_b.template internal<false>());
293 }
294
301 template<class t_type, class t_angle_type>
302 constexpr static Angle<t_angle_type> operator*(const Angle<t_angle_type>& angle, t_type mult)
303 {
304 return Angle<t_angle_type>(cast<t_angle_type>(cast<t_type>(angle.template internal<false>()) * mult));
305 }
306
313 template<class t_type, class t_angle_type>
314 constexpr static Angle<t_angle_type> operator*(t_type mult, const Angle<t_angle_type>& angle)
315 {
316 return Angle<t_angle_type>(cast<t_angle_type>(cast<t_type>(angle.template internal<false>()) * mult));
317 }
318
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)
327 {
328 t_vector_type product;
329 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
330 product[dim] = angle[dim] * mult;
331 return product;
332 }
333
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)
343 {
344 t_vector_type product;
345 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
346 product[dim] = angle[dim] * mult;
347 return product;
348 }
349
356 template<uint01 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
358 operator*(const t_vector_type& angle, const Vector<t_dims, t_type>& mult)
359 {
360 t_vector_type product;
361 for (uint01 dim = 0; dim < t_dims; ++dim)
362 product[dim] = angle[dim] * mult[dim];
363 return product;
364 }
365
372 template<uint01 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
374 operator*(const t_vector_type& angle, const Vector<t_dims, t_type>& mult)
375 {
376 t_vector_type product;
377 for (uint01 dim = 0; dim < t_dims; ++dim)
378 product[dim] = angle[dim] * mult[dim];
379 return product;
380 }
381
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)
391 {
392 t_vector_type product;
393 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
394 product[dim] = mult * angle[dim];
395 return product;
396 }
397
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)
406 {
407 t_vector_type product;
408 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
409 product[dim] = mult * angle[dim];
410 return product;
411 }
412
418 template<uint01 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
420 operator*(const Vector<t_dims, t_type>& mult, const t_vector_type& angle)
421 {
422 t_vector_type product;
423 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
424 product[dim] = mult[dim] * angle[dim];
425 return product;
426 }
427
433 template<uint01 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
435 operator*(const Vector<t_dims, t_type>& mult, const t_vector_type& angle)
436 {
437 t_vector_type product;
438 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
439 product[dim] = mult[dim] * angle[dim];
440 return product;
441 }
442
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)
451 {
452 t_vector_type product;
453 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
454 product[dim] = mult[dim] * angle[dim];
455 return product;
456 }
457
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)
466 {
467 t_vector_type product;
468 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
469 product[dim] = mult[dim] * angle[dim];
470 return product;
471 }
472
478 template<class t_type, class t_angle_type>
479 constexpr static Angle<t_angle_type> operator/(const Angle<t_angle_type>& num, t_type den)
480 {
481 return Angle<t_angle_type>(cast<t_angle_type>(cast<t_type>(num.template internal<false>()) / den));
482 }
483
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)
493 {
494 t_vector_type div;
495 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
496 div[dim] = angle[dim] / den;
497 return div;
498 }
499
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)
509 {
510 t_vector_type div;
511 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
512 div[dim] = angle[dim] / den;
513 return div;
514 }
515
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)
525 {
526 t_vector_type div;
527 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
528 div[dim] = angle[dim] / den;
529 return div;
530 }
531
538 template<uint01 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
540 operator/(const t_vector_type& angle, const Vector<t_dims, t_type>& den)
541 {
542 t_vector_type div;
543 for (uint01 dim = 0; dim < t_dims; ++dim)
544 div[dim] = angle[dim] / den[dim];
545 return div;
546 }
547
554 template<uint01 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
556 operator/(const t_vector_type& angle, const Vector<t_dims, Angle<t_angle_type>>& den)
557 {
559 for (uint01 dim = 0; dim < t_dims; ++dim)
560 div[dim] = angle[dim] / den[dim];
561 return div;
562 }
563
569 template<uint01 t_dims, class t_angle_type>
570 constexpr Vector<t_dims, fltp08> operator/(const Vector<t_dims, Angle<t_angle_type>>& angle, const Vector<t_dims, Angle<t_angle_type>>& den)
571 {
573 for (uint01 dim = 0; dim < t_dims; ++dim)
574 div[dim] = angle[dim] / den[dim];
575 return div;
576 }
577
584 template<class t_type, class t_angle_type>
585 constexpr static Angle<t_angle_type> operator/(t_type num, const Angle<t_angle_type>& den)
586 {
587 return Angle(cast<t_angle_type>(num / cast<t_type>(den.template internal<false>())));
588 }
589
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
597 operator/(t_type num, const t_vector_type& angle)
598 {
599 t_vector_type div;
600 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
601 div[dim] = num / angle[dim];
602 return div;
603 }
604
610 template<class t_angle_type>
612 {
613 angle = angle + add;
614 return angle;
615 }
616
622 template<class t_angle_type>
624 {
625 angle = angle - sub;
626 return angle;
627 }
628
634 template<class t_type, class t_angle_type>
635 constexpr static Angle<t_angle_type>& operator*=(Angle<t_angle_type>& angle, const t_type& mult)
636 {
637 angle = angle * mult;
638 return angle;
639 }
640
646 template<uint01 t_dims, class t_type, class t_angle_type>
647 constexpr static Vector<t_dims, Angle<t_angle_type>>& operator*=(Vector<t_dims, Angle<t_angle_type>>& angle, const t_type& mult)
648 {
649 for (uint01 dim = 0; dim < t_dims; ++dim)
650 angle[dim] = angle[dim] * mult;
651 return angle;
652 }
653
659 template<uint01 t_dims, class t_type, class t_angle_type>
661 {
662 for (uint01 dim = 0; dim < t_dims; ++dim)
663 angle[dim] = angle[dim] * mult[dim];
664 return angle;
665 }
666
672 template<class t_angle_type>
674 {
675 angle = angle * mult;
676 return angle;
677 }
678
685 template<class t_type, class t_angle_type>
686 constexpr static Angle<t_angle_type>& operator/=(Angle<t_angle_type>& angle, const t_type& mult)
687 {
688 angle = angle / mult;
689 return angle;
690 }
691
697 template<uint01 t_dims, class t_type, class t_angle_type>
698 constexpr static Vector<t_dims, Angle<t_angle_type>>& operator/=(Vector<t_dims, Angle<t_angle_type>>& angle, const t_type& den)
699 {
700 for (uint01 dim = 0; dim < t_dims; ++dim)
701 angle[dim] = angle[dim] / den;
702 return angle;
703 }
704
710 template<uint01 t_dims, class t_type, class t_angle_type>
712 {
713 for (uint01 dim = 0; dim < t_dims; ++dim)
714 angle[dim] = angle[dim] / den[dim];
715 return angle;
716 }
717
724 template<uint01 t_dims, class t_angle_type>
726 {
728 for (uint01 dim = 0; dim < t_dims; ++dim)
729 mod[dim] = Angle<t_angle_type>(cast<t_angle_type>(vec_a[dim].template internal<false>() % vec_b[dim].template internal<false>()));
730 return mod;
731 }
732
738 template<uint01 t_dims, class t_angle_type>
740 {
742 for (uint01 dim = 0; dim < t_dims; ++dim)
743 mod[dim] = Angle<t_angle_type>(cast<t_angle_type>(vec_a[dim].template internal<false>() % value_b.template internal<false>()));
744 return mod;
745 }
746
752 template<class t_angle_type>
754 {
755 return value >= Angle<t_angle_type>(0) ? value : -value;
756 }
757
758
764 template<class t_new_type, uint01 t_dims, class t_angle_type>
766 {
768 for(uint01 dim = 0; dim < t_dims; ++dim)
769 angle[dim] = old[dim].template toTypeAngle<t_new_type>();
770 return angle;
771 }
772
777 class NDEVR_BASE_API AngleDefinitions
778 {
779 public:
792
808 template<class t_angle_type, uint01 t_dims, class t_type>
810 {
811 const Vector<t_dims, t_type> v_left(left - middle);
812 const Vector<t_dims, t_type> v_right(right - middle);
813 return Angle<t_angle_type>(RADIANS, acos(dot(v_left, v_right) / cast<fltp08>(sqrt(v_left.magnitudeSquared() * v_right.magnitudeSquared()))));
814 }
815
828 template<class t_angle_type>
830 {
831 return Angle<t_angle_type>::atan(cast<fltp08>(sqrt(tan(roll) * tan(roll) + tan(pitch) * tan(pitch))));
832 }
833
839 template<class t_angle_type, uint01 t_dims, class t_type>
841 {
842 const Vector<2, t_type> xy_diff = ray.template as<2, t_type>();
843 return Angle<t_angle_type>::atan2(ray[Z], xy_diff.template magnitude<t_type>());
844 }
845
851 template<class t_angle_type, uint01 t_dims, class t_type>
853 {
854 return Angle<t_angle_type>::atan2(ray[Y], ray[X]);
855 }
856
862 template<class t_angle_type, uint01 t_dims, class t_type>
864 {
865 t_type dot_product = dot(a, b);
866 t_type length = a.template magnitude<t_type>() * b.template magnitude<t_type>();
867 t_type cos_theta = clip(dot_product / length, cast<t_type>(-1), cast<t_type>(1));
868 return Angle<t_angle_type>::acos(cos_theta);
869 }
870
877 template<class t_angle_type, uint01 t_dims, class t_type>
879 {
881 for (uint01 i = 0; i < t_dims; i++)
882 orient_vector[i] = Angle<t_angle_type>(angle_type, ray[i]);
883 return orient_vector;
884 }
885
891 template<bool t_normalized, uint01 t_dims, class t_angle_type>
892 static constexpr Vector<t_dims, fltp08> Orientation(AngleType angle_type, const Vector<t_dims, Angle<t_angle_type>>& ray)
893 {
894 Vector<t_dims, fltp08> orient_vector;
895 for (uint01 i = 0; i < t_dims; i++)
896 orient_vector[i] = ray[i].as(angle_type);
897 return orient_vector;
898 }
899
913 template<class t_angle_type, class t_type>
915 {
916 Angle<t_angle_type> pitch(RADIANS, (cast<fltp08>(asin((normal[Y] * sin(yaw) + normal[X] * cos(yaw))))));
918 if (::fabs(cos(pitch)) < 0.001)
919 roll = Angle<t_angle_type>(DEGREES, 0.0);
920 else if (::fabs(cos(yaw)) < 0.01)
921 roll = Angle<t_angle_type>(RADIANS, cast<fltp08>(-asin((cos(yaw) * sin(pitch) - normal[X]) / cos(pitch) * -sin(yaw))));
922 else
923 roll = Angle<t_angle_type>(RADIANS, cast<fltp08>(-asin((-normal[Y] + sin(yaw) * sin(pitch)) / (cos(pitch) * cos(yaw)))));
924 if (normal[Z] < 0)
925 roll = Angle<t_angle_type>(DEGREES, 180.0) - roll;
926 return Vector<3, Angle<t_angle_type>>(roll, pitch, yaw);
927 }
928
935 template<class t_angle_type>
937 {
938 fltp08 suggested_pitch_value = angle[PITCH].template as<DEGREES>();
939 fltp08 our_pitch_value = reference[PITCH].template as<DEGREES>();
940
941 fltp08 suggested_yaw_value = angle[YAW].template as<DEGREES>();
942 fltp08 our_yaw_value = reference[YAW].template as<DEGREES>();
943
944 fltp08 suggested_roll_value = angle[ROLL].template as<DEGREES>();
945 fltp08 our_roll_value = reference[ROLL].template as<DEGREES>();
946
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;
951
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;
956
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;
961
962 bool flip = std::abs(suggested_roll_value - our_roll_value) >= 90.0 && std::abs(suggested_yaw_value - our_yaw_value) >= 90.0;
963 if (flip)
964 {
965 angle[ROLL] = Angle<fltp08>(DEGREES, angle[ROLL].template as<DEGREES>() - 180);
966 angle[YAW] = Angle<fltp08>(DEGREES, angle[YAW].template as<DEGREES>() - 180);
967 }
968 return angle;
969 }
970
971 public:
981 static const fltp08* CalcIndexSin();
982 };
983
990 template<uint01 t_dims, class t_angle_type>
995
1002 template<uint01 t_dims, class t_angle_type>
1007};
1008
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.
Definition Angle.h:83
static Angle atan(t_value_type value)
Computes the principal value of the arc tangent of the given value.
Definition Angle.h:288
static Angle acos(t_value_type value)
Computes the principal value of the arc cosine of the given value.
Definition Angle.h:266
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)
Definition Angle.h:300
static constexpr sint04 INDEX_PI
Optimized angle constant representing PI; allows integers to store angles to some degree of accuracy.
Definition Angle.h:305
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
constexpr t_type magnitudeSquared() const
Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
Definition Vector.hpp:448
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).
Definition Angle.h:47
@ PITCH
Rotation about the lateral axis (Y).
Definition Angle.h:46
@ ROLL
Rotation about the forward axis (X).
Definition Angle.h:45
@ type
The type identifier string for this model node.
Definition Model.h:58
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.
Definition Angle.h:56
@ DEGREES
Angle measured in degrees (0 to 360 for a full circle).
Definition Angle.h:58
@ INTERNAL_ANGLE
The angle internally used by the angle class.
Definition Angle.h:59
@ RADIANS
Angle measured in radians (0 to 2*PI for a full circle).
Definition Angle.h:57
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.
Definition Angle.h:408
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.