API Documentation
Loading...
Searching...
No Matches
AngleFunctions.h
Go to the documentation of this file.
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>
36/**--------------------------------------------------------------------------------------------------
37Namespace: Parke
38Namespace that wraps all Logic created by Tyler Parke
39 *-----------------------------------------------------------------------------------------------**/
40
41namespace NDEVR
42{
43 extern NDEVR_BASE_API const fltp08* const s_index_sin;
44 /**--------------------------------------------------------------------------------------------------
45 Fn: static bool operator>(const Angle& angle_a, const Angle& angle_b)
46
47 Greater-than comparison operator.
48
49 Author: Tyler Parke
50
51 Date: 2017-11-13
52
53 Parameters:
54 angle_a - The first instance to compare.
55 angle_b - The second instance to compare.
56
57 Returns: True if the first parameter is greater than to the second.
58 *-----------------------------------------------------------------------------------------------**/
59 template<class t_type_a, class t_type_b>
60 constexpr static bool operator>(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
61 {
62 return angle_a.template internal<false>() > cast<t_type_a>(angle_b.template internal<false>());
63 }
64 /** . */
65 template<class t_type_a, class t_type_b>
66 constexpr static bool operator<(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
67 {
68 return angle_a.template internal<false>() < cast<t_type_a>(angle_b.template internal<false>());
69 }
70
71 /**--------------------------------------------------------------------------------------------------
72 Fn: static bool operator>=(const Angle& angle_a, const Angle& angle_b)
73
74 Greater-than-or-equal comparison operator.
75
76 Author: Tyler Parke
77
78 Date: 2017-11-13
79
80 Parameters:
81 angle_a - The first instance to compare.
82 angle_b - The second instance to compare.
83
84 Returns: True if the first parameter is greater than or equal to the second.
85 *-----------------------------------------------------------------------------------------------**/
86 template<class t_type_a, class t_type_b>
87 constexpr static bool operator>=(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
88 {
89 return angle_a.template internal<false>() >= cast<t_type_a>(angle_b.template internal<false>());
90 }
91 /** . */
92 template<class t_type_a, class t_type_b>
93 constexpr static bool operator<=(const Angle<t_type_a>& angle_a, const Angle<t_type_b>& angle_b)
94 {
95 return angle_a.template internal<false>() <= cast<t_type_a>(angle_b.template internal<false>());
96 }
97 /**--------------------------------------------------------------------------------------------------
98 Fn: fltp08 sin(const Angle& angle);
99
100 Sines the given angle.
101
102 Author: Tyler Parke.
103
104 Date: 2017-11-13.
105
106 Parameters:
107 angle - The angle to perform sin on.
108
109 Returns: The sine of the given angle
110
111 *-----------------------------------------------------------------------------------------------**/
112 template<class t_type>
113 typename std::enable_if<!ObjectInfo<t_type>::Float, fltp08>::type sin(const Angle<t_type>& angle)
114 {
115
116 const uint02 internal_angle = cast<uint02>(angle.template internal<true>());
117 if (internal_angle <= Angle<t_type>::INDEX_PI)
118 {
119 if (internal_angle > (Angle<t_type>::INDEX_PI / 2))
120 return s_index_sin[Angle<t_type>::INDEX_PI - internal_angle];
121 else
122 return s_index_sin[internal_angle];
123 }
124 else
125 {
126 if (internal_angle >= Angle<t_type>::INDEX_PI + (Angle<t_type>::INDEX_PI / 2))
127 return -s_index_sin[2 * Angle<t_type>::INDEX_PI - internal_angle];
128 else
129 return -s_index_sin[internal_angle - Angle<t_type>::INDEX_PI];
130 }
131 }
132
133 template<class t_type>
134 typename std::enable_if<ObjectInfo<t_type>::Float, fltp08>::type sin(const Angle<t_type>& angle)
135 {
136 return ::sin(angle.template as<RADIANS>());
137 }
138
139 /**--------------------------------------------------------------------------------------------------
140 Fn: extern fltp08 cos(const Angle& angle);
141
142 Cosines the given angle.
143
144 Author: Tyler Parke
145
146 Date: 2017-11-13
147
148 Parameters:
149 angle - The angle to perform cosine on.
150
151 Returns: The cosine of the given angle.
152 *-----------------------------------------------------------------------------------------------**/
153 template<class t_type>
154 typename std::enable_if<!ObjectInfo<t_type>::Float, fltp08>::type cos(const Angle<t_type>& angle)
155 {
156 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)));
157 return sin(internal_angle);
158 }
159
160 template<class t_type>
161 typename std::enable_if<ObjectInfo<t_type>::Float, fltp08>::type cos(const Angle<t_type>& angle)
162 {
163 return ::cos(angle.template as<RADIANS>());
164 }
165
166 /**--------------------------------------------------------------------------------------------------
167 Fn: extern fltp08 tan(const Angle& angle);
168
169 Tangents the given angle.
170
171 Author: Tyler Parke
172
173 Date: 2017-11-13
174
175 Parameters:
176 angle - The angle to perform tan on.
177
178 Returns: The tangent of a given angle, or undefined when tangent is not defined.
179 *-----------------------------------------------------------------------------------------------**/
180
181 template<class t_type>
182 typename std::enable_if<!ObjectInfo<t_type>::Float, fltp08>::type tan(const Angle<t_type>& angle)
183 {
184 return sin(angle) / cos(angle);
185 }
186
187 template<class t_type>
188 typename std::enable_if<ObjectInfo<t_type>::Float, fltp08>::type tan(const Angle<t_type>& angle)
189 {
190 return ::tan(angle.template as<RADIANS>());
191 }
192
193 /**--------------------------------------------------------------------------------------------------
194 Fn: t_type sin(const t_type& angle)
195
196 Sines the given angle.
197
198 Author: Tyler Parke
199
200 Date: 2017-11-13
201
202 Parameters:
203 angle - The angle.
204
205 Returns: A t_type.
206 *-----------------------------------------------------------------------------------------------**/
207 template<class t_type>
208 t_type sin(const t_type& angle)
209 {
210 return ::sin(angle);
211 }
212
213 /**--------------------------------------------------------------------------------------------------
214 Fn: t_type cos(const t_type& angle)
215
216 Cosines the given angle.
217
218 Author: Tyler Parke
219
220 Date: 2017-11-13
221
222 Parameters:
223 angle - The angle.
224
225 Returns: A t_type.
226 *-----------------------------------------------------------------------------------------------**/
227 template<class t_type>
228 t_type cos(const t_type& angle)
229 {
230 return ::cos(angle);
231 }
232
233 /**--------------------------------------------------------------------------------------------------
234 Fn: t_type tan(const t_type& angle)
235
236 Tangents the given angle.
237
238 Author: Tyler Parke
239
240 Date: 2017-11-13
241
242 Parameters:
243 angle - The angle.
244
245 Returns: A t_type.
246 *-----------------------------------------------------------------------------------------------**/
247 template<class t_type>
248 t_type tan(const t_type& angle)
249 {
250 return ::tan(angle);
251 }
252
253 /**--------------------------------------------------------------------------------------------------
254 Fn: static Angle operator-(const Angle& angle_a, const Angle& angle_b)
255
256 Subtraction operator.
257
258 Author: Tyler Parke
259
260 Date: 2017-11-13
261
262 Parameters:
263 angle_a - The first value.
264 angle_b - A value to subtract from it.
265
266 Returns: The result of the operation.
267 *-----------------------------------------------------------------------------------------------**/
268 template<class t_type>
269 constexpr static Angle<t_type> operator-(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
270 {
271 return Angle<t_type>(cast<t_type>(angle_a.template internal<false>() - angle_b.template internal<false>()));
272 }
273 /**--------------------------------------------------------------------------------------------------
274 Fn: static Angle operator+(const Angle& angle_a, const Angle& angle_b)
275
276 Addition operator.
277
278 Author: Tyler Parke
279
280 Date: 2017-11-13
281
282 Parameters:
283 angle_a - The first value.
284 angle_b - A value to add to it.
285
286 Returns: The result of the operation.
287 *-----------------------------------------------------------------------------------------------**/
288 template<class t_type>
289 constexpr static Angle<t_type> operator+(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
290 {
291 return Angle<t_type>(cast<t_type>(angle_a.template internal<false>() + angle_b.template internal<false>()));
292 }
293
294 template<class t_type>
295 constexpr static Angle<t_type> difference(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
296 {
297 Angle<t_type> angle = (angle_a - angle_b).normalized();
298 if (angle <= Angle<t_type>(DEGREES, 180.0f))
299 return angle;
300 else
301 return Angle<t_type>(DEGREES, -360.0f) + angle;
302 }
303 template<uint01 t_dims, class t_type>
304 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)
305 {
306 Vector<t_dims, Angle<t_type>> angle;
307 for (uint01 dim = 0; dim < t_dims; ++dim)
308 {
309 angle[dim] = difference(angle_a[dim], angle_b[dim]);
310 }
311 return angle;
312 }
313
314 template<class t_type>
315 constexpr static Angle<t_type> Average(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
316 {
317 Angle<t_type> angle = difference(angle_a, angle_b) / 2.0;
318 angle += angle_b;
319 return angle;
320 }
321
322 template<uint01 t_dims, class t_type>
323 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)
324 {
325 Vector<t_dims, Angle<t_type>> angle;
326 for (uint01 dim = 0; dim < t_dims; ++dim)
327 {
328 angle[dim] = Average(angle_a[dim], angle_b[dim]);
329 }
330 return angle;
331 }
332
333
334 /**--------------------------------------------------------------------------------------------------
335 Fn: static Angle operator*(const Angle& angle_a, const Angle& angle_b)
336
337 Multiplication operator.
338
339 Author: Tyler Parke
340
341 Date: 2017-11-13
342
343 Parameters:
344 angle_a - The first value to multiply.
345 angle_b - The second value to multiply.
346
347 Returns: The result of the operation.
348 *-----------------------------------------------------------------------------------------------**/
349 template<class t_type>
350 constexpr static Angle<t_type> operator*(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
351 {
352 return Angle<t_type>(cast<t_type>(angle_a.template internal<false>() * angle_b.template internal<false>()));
353 }
354
355 /**--------------------------------------------------------------------------------------------------
356 Fn: static Angle operator/(const Angle& angle_a, const Angle& angle_b)
357
358 Division operator.
359
360 Author: Tyler Parke
361
362 Date: 2017-11-13
363
364 Parameters:
365 angle_a - The numerator.
366 angle_b - The denominator.
367
368 Returns: The result of the operation.
369 *-----------------------------------------------------------------------------------------------**/
370 template<class t_type>
371 constexpr static fltp08 operator/(const Angle<t_type>& angle_a, const Angle<t_type>& angle_b)
372 {
373 return cast<fltp08>(angle_a.template internal<false>()) / cast<fltp08>(angle_b.template internal<false>());
374 }
375
376 /**--------------------------------------------------------------------------------------------------
377 Fn: static Angle operator*(const Angle& angle, t_type mult)
378
379 Multiplication operator.
380
381 Author: Tyler Parke
382
383 Date: 2017-11-13
384
385 Parameters:
386 angle - The first value to multiply.
387 mult - The second value to multiply.
388
389 Returns: The result of the operation.
390 *-----------------------------------------------------------------------------------------------**/
391 template<class t_type, class t_angle_type>
392 constexpr static Angle<t_angle_type> operator*(const Angle<t_angle_type>& angle, t_type mult)
393 {
394 return Angle<t_angle_type>(cast<t_angle_type>(cast<t_type>(angle.template internal<false>()) * mult));
395 }
396 template<class t_type, class t_angle_type>
397 constexpr static Angle<t_angle_type> operator*(t_type mult, const Angle<t_angle_type>& angle)
398 {
399 return Angle<t_angle_type>(cast<t_angle_type>(cast<t_type>(angle.template internal<false>()) * mult));
400 }
401 template<class t_type, class t_vector_type>
402 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>::type
403 operator*(const t_vector_type& angle, const t_type& mult)
404 {
405 t_vector_type product;
406 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
407 product[dim] = angle[dim] * mult;
408 return product;
409 }
410 template<class t_type, class t_vector_type>
411 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>::type
412 operator*(const t_vector_type& angle, const t_type& mult)
413 {
414 t_vector_type product;
415 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
416 product[dim] = angle[dim] * mult;
417 return product;
418 }
419 template<uint01 t_dims, class t_type, class t_vector_type>
420 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<fltp08>>, t_vector_type>::value, t_vector_type>::type
421 operator*(const t_vector_type& angle, const Vector<t_dims, t_type>& mult)
422 {
423 t_vector_type product;
424 for (uint01 dim = 0; dim < t_dims; ++dim)
425 product[dim] = angle[dim] * mult[dim];
426 return product;
427 }
428 template<uint01 t_dims, class t_type, class t_vector_type>
429 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<sint04>>, t_vector_type>::value, t_vector_type>::type
430 operator*(const t_vector_type& angle, const Vector<t_dims, t_type>& mult)
431 {
432 t_vector_type product;
433 for (uint01 dim = 0; dim < t_dims; ++dim)
434 product[dim] = angle[dim] * mult[dim];
435 return product;
436 }
437 /**--------------------------------------------------------------------------------------------------
438 Fn: static Angle operator/(const Angle& num, t_type den)
439
440 Division operator.
441
442 Author: Tyler Parke
443
444 Date: 2017-11-13
445
446 Parameters:
447 num - The numerator.
448 den - The denominator.
449
450 Returns: The result of the operation.
451 *-----------------------------------------------------------------------------------------------**/
452 template<class t_type, class t_angle_type>
453 constexpr static Angle<t_angle_type> operator/(const Angle<t_angle_type>& num, t_type den)
454 {
455 return Angle<t_angle_type>(cast<t_angle_type>(cast<t_type>(num.template internal<false>()) / den));
456 }
457 template<class t_type, class t_vector_type, class t_angle_type>
458 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<t_angle_type>>::value, t_vector_type>::type
459 operator/(const t_vector_type& angle, const t_type& den)
460 {
461 t_vector_type div;
462 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
463 div[dim] = angle[dim] / den;
464 return div;
465 }
466 template<class t_type, class t_vector_type>
467 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>::type
468 operator/(const t_vector_type& angle, const t_type& den)
469 {
470 t_vector_type div;
471 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
472 div[dim] = angle[dim] / den;
473 return div;
474 }
475 template<class t_type, class t_vector_type>
476 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>::type
477 operator/(const t_vector_type& angle, const t_type& den)
478 {
479 t_vector_type div;
480 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
481 div[dim] = angle[dim] / den;
482 return div;
483 }
484 template<uint01 t_dims, class t_type, class t_vector_type, class t_angle_type>
485 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<t_angle_type>>, t_vector_type>::value, t_vector_type>::type
486 operator/(const t_vector_type& angle, const Vector<t_dims, t_type>& den)
487 {
488 t_vector_type div;
489 for (uint01 dim = 0; dim < t_dims; ++dim)
490 div[dim] = angle[dim] / den[dim];
491 return div;
492 }
493 template<uint01 t_dims, class t_vector_type, class t_angle_type>
494 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
495 operator/(const t_vector_type& angle, const Vector<t_dims, Angle<t_angle_type>>& den)
496 {
498 for (uint01 dim = 0; dim < t_dims; ++dim)
499 div[dim] = angle[dim] / den[dim];
500 return div;
501 }
502 template<uint01 t_dims, class t_angle_type>
503 constexpr Vector<t_dims, fltp08> operator/(const Vector<t_dims, Angle<t_angle_type>>& angle, const Vector<t_dims, Angle<t_angle_type>>& den)
504 {
506 for (uint01 dim = 0; dim < t_dims; ++dim)
507 div[dim] = angle[dim] / den[dim];
508 return div;
509 }
510 /**--------------------------------------------------------------------------------------------------
511 Fn: static Angle operator*(t_type mult, const Angle& angle)
512
513 Multiplication operator.
514
515 Author: Tyler Parke
516
517 Date: 2017-11-13
518
519 Parameters:
520 mult - The first value to multiply.
521 angle - The second value to multiply.
522
523 Returns: The result of the operation.
524 *-----------------------------------------------------------------------------------------------**/
525 template<class t_type, class t_vector_type>
526 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>::type
527 operator*(const t_type& mult, const t_vector_type& angle)
528 {
529 t_vector_type product;
530 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
531 product[dim] = mult * angle[dim];
532 return product;
533 }
534 template<class t_type, class t_vector_type>
535 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>::type
536 operator*(const t_type& mult, const t_vector_type& angle)
537 {
538 t_vector_type product;
539 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
540 product[dim] = mult * angle[dim];
541 return product;
542 }
543 template<uint01 t_dims, class t_type, class t_vector_type>
544 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<fltp08>>, t_vector_type>::value, t_vector_type>::type
545 operator*(const Vector<t_dims, t_type>& mult, const t_vector_type& angle)
546 {
547 t_vector_type product;
548 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
549 product[dim] = mult[dim] * angle[dim];
550 return product;
551 }
552 template<uint01 t_dims, class t_type, class t_vector_type>
553 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, Angle<sint04>>, t_vector_type>::value, t_vector_type>::type
554 operator*(const Vector<t_dims, t_type>& mult, const t_vector_type& angle)
555 {
556 t_vector_type product;
557 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
558 product[dim] = mult[dim] * angle[dim];
559 return product;
560 }
561 template<class t_type, class t_vector_type>
562 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<fltp08>>::value, t_vector_type>::type
563 operator*(const t_vector_type& mult, const t_vector_type& angle)
564 {
565 t_vector_type product;
566 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
567 product[dim] = mult[dim] * angle[dim];
568 return product;
569 }
570 template<class t_type, class t_vector_type>
571 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<sint04>>::value, t_vector_type>::type
572 operator*(const t_vector_type& mult, const t_vector_type& angle)
573 {
574 t_vector_type product;
575 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
576 product[dim] = mult[dim] * angle[dim];
577 return product;
578 }
579 /**--------------------------------------------------------------------------------------------------
580 Fn: static Angle operator/(t_type num, const Angle& den)
581
582 Division operator.
583
584 Author: Tyler Parke
585
586 Date: 2017-11-13
587
588 Parameters:
589 num - The numerator.
590 den - The denominator.
591
592 Returns: The result of the operation.
593 *-----------------------------------------------------------------------------------------------**/
594 template<class t_type, class t_angle_type>
595 constexpr static Angle<t_angle_type> operator/(t_type num, const Angle<t_angle_type>& den)
596 {
597 return Angle(cast<t_angle_type>(num / cast<t_type>(den.template internal<false>())));
598 }
599 template<class t_type, class t_vector_type, class t_angle_type>
600 constexpr typename std::enable_if<IsVecType<t_vector_type, Angle<t_angle_type>>::value, t_vector_type>::type
601 operator/(t_type num, const t_vector_type& angle)
602 {
603 t_vector_type div;
604 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
605 div[dim] = num / angle[dim];
606 return div;
607 }
608
609
610 /**--------------------------------------------------------------------------------------------------
611 Fn: static Angle& operator+=(Angle& angle, const Angle& add)
612
613 Addition assignment operator.
614
615 Author: Tyler Parke
616
617 Date: 2017-11-13
618
619 Parameters:
620 angle - [in,out] The angle.
621 add - The add.
622
623 Returns: The result of the operation.
624 *-----------------------------------------------------------------------------------------------**/
625 template<class t_angle_type>
626 constexpr static Angle<t_angle_type>& operator+=(Angle<t_angle_type>& angle, const Angle<t_angle_type>& add)
627 {
628 angle = angle + add;
629 return angle;
630 }
631
632 /**--------------------------------------------------------------------------------------------------
633 Fn: static Angle& operator-=(Angle& angle, const Angle& sub)
634
635 Subtraction assignment operator.
636
637 Author: Tyler Parke
638
639 Date: 2017-11-13
640
641 Parameters:
642 angle - [in,out] The angle.
643 sub - The sub.
644
645 Returns: The result of the operation.
646 *-----------------------------------------------------------------------------------------------**/
647 template<class t_angle_type>
648 constexpr static Angle<t_angle_type>& operator-=(Angle<t_angle_type>& angle, const Angle<t_angle_type>& sub)
649 {
650 angle = angle - sub;
651 return angle;
652 }
653
654 /**--------------------------------------------------------------------------------------------------
655 Fn: static Angle& operator*=(Angle& angle, fltp04 mult)
656
657 Multiplication assignment operator.
658
659 Author: Tyler Parke
660
661 Date: 2017-11-13
662
663 Parameters:
664 angle - [in,out] The angle.
665 mult - The multiply.
666
667 Returns: The result of the operation.
668 *-----------------------------------------------------------------------------------------------**/
669 template<class t_type, class t_angle_type>
670 constexpr static Angle<t_angle_type>& operator*=(Angle<t_angle_type>& angle, const t_type& mult)
671 {
672 angle = angle * mult;
673 return angle;
674 }
675 template<uint01 t_dims, class t_type, class t_angle_type>
676 constexpr static Vector<t_dims, Angle<t_angle_type>>& operator*=(Vector<t_dims, Angle<t_angle_type>>& angle, const t_type& mult)
677 {
678 for (uint01 dim = 0; dim < t_dims; ++dim)
679 angle[dim] = angle[dim] * mult;
680 return angle;
681 }
682 template<uint01 t_dims, class t_type, class t_angle_type>
683 constexpr static Vector<t_dims, Angle<t_angle_type>>& operator*=(Vector<t_dims, Angle<t_angle_type>>& angle, const Vector<t_dims, t_type>& mult)
684 {
685 for (uint01 dim = 0; dim < t_dims; ++dim)
686 angle[dim] = angle[dim] * mult[dim];
687 return angle;
688 }
689
690 /**--------------------------------------------------------------------------------------------------
691 Fn: static Angle& operator*=(Angle& angle, const Angle& mult)
692
693 Multiplication assignment operator.
694
695 Author: Tyler Parke
696
697 Date: 2017-11-13
698
699 Parameters:
700 angle - [in,out] The angle.
701 mult - The multiply.
702
703 Returns: The result of the operation.
704 *-----------------------------------------------------------------------------------------------**/
705 template<class t_angle_type>
706 constexpr static Angle<t_angle_type>& operator*=(Angle<t_angle_type>& angle, const Angle<t_angle_type>& mult)
707 {
708 angle = angle * mult;
709 return angle;
710 }
711
712 template<class t_type, class t_angle_type>
713 constexpr static Angle<t_angle_type>& operator/=(Angle<t_angle_type>& angle, const t_type& mult)
714 {
715 angle = angle / mult;
716 return angle;
717 }
718 template<uint01 t_dims, class t_type, class t_angle_type>
719 constexpr static Vector<t_dims, Angle<t_angle_type>>& operator/=(Vector<t_dims, Angle<t_angle_type>>& angle, const t_type& den)
720 {
721 for (uint01 dim = 0; dim < t_dims; ++dim)
722 angle[dim] = angle[dim] / den;
723 return angle;
724 }
725 template<uint01 t_dims, class t_type, class t_angle_type>
726 constexpr static Vector<t_dims, Angle<t_angle_type>>& operator/=(Vector<t_dims, Angle<t_angle_type>>& angle, const Vector<t_dims, t_type>& den)
727 {
728 for (uint01 dim = 0; dim < t_dims; ++dim)
729 angle[dim] = angle[dim] / den[dim];
730 return angle;
731 }
732
733 template<uint01 t_dims, class t_angle_type>
735 {
737 for (uint01 dim = 0; dim < t_dims; ++dim)
738 mod[dim] = Angle<t_angle_type>(cast<t_angle_type>(vec_a[dim].template internal<false>() % vec_b[dim].template internal<false>()));
739 return mod;
740 }
741 template<uint01 t_dims, class t_angle_type>
743 {
745 for (uint01 dim = 0; dim < t_dims; ++dim)
746 mod[dim] = Angle<t_angle_type>(cast<t_angle_type>(vec_a[dim].template internal<false>() % value_b.template internal<false>()));
747 return mod;
748 }
749 template<class t_angle_type>
751 {
752 return value >= Angle<t_angle_type>(0) ? value : -value;
753 }
754
755
756
757 template<class t_new_type, uint01 t_dims, class t_angle_type>
759 {
761 for(uint01 dim = 0; dim < t_dims; ++dim)
762 angle[dim] = old[dim].template toTypeAngle<t_new_type>();
763 return angle;
764 }
765
766 /**--------------------------------------------------------------------------------------------------
767 Class: AngleDefinitions
768
769 \brief Logic for converting between Euler angles and basic rotations or normals
770
771 Author: Tyler Parke
772
773 Date: 2017-11-13
774 *-----------------------------------------------------------------------------------------------**/
775
777 {
778 public:
779
780 /**--------------------------------------------------------------------------------------------------
781 Fn: static Vector<3, Angle> AngleDefinitions::QuaternionToOrientation(const Vector<4, fltp08>& q);
782
783 Convert quaternion to roll pitch yaw.
784
785 Author: Tyler Parke
786
787 Date: 2017-11-13
788
789 Parameters:
790 q - A Vector&lt;4,fltp08&gt; to process.
791
792 Returns: The quaternion converted to roll pitch yaw.
793 *-----------------------------------------------------------------------------------------------**/
794
795 static Vector<3, Angle<fltp08>> QuaternionToOrientation(const Vector<4, fltp08>& quaternion);
796
797 /**--------------------------------------------------------------------------------------------------
798 Fn: static Angle AngleDefinitions::Rotation(const Vector<t_dims, t_type>& left,
799 const Vector<t_dims, t_type>& middle, const Vector<t_dims, t_type>& right)
800
801 Gets a rotation.
802
803 Author: Tyler Parke
804
805 Date: 2017-11-13
806
807 Parameters:
808 left - The left.
809 middle - The middle.
810 right - The right.
811
812 Returns: The rotation.
813 *-----------------------------------------------------------------------------------------------**/
814 template<class t_angle_type, uint01 t_dims, class t_type>
816 {
817 const Vector<t_dims, t_type> v_left(left - middle);
818 const Vector<t_dims, t_type> v_right(right - middle);
819 return Angle<t_angle_type>(RADIANS, acos(dot(v_left, v_right) / cast<fltp08>(sqrt(v_left.magnitudeSquared() * v_right.magnitudeSquared()))));
820 }
821 /**--------------------------------------------------------------------------------------------------
822 Fn: static Angle AngleDefinitions::Inclination(const Angle& roll, const Angle& pitch)
823
824 Gets the Inclination of .
825
826 Author: Tyler Parke
827
828 Date: 2018-08-15
829
830 Parameters:
831 roll - The rotation about the X axis.
832 pitch - The rotation about the Y axis.
833
834 Returns: The rotation.
835 *-----------------------------------------------------------------------------------------------**/
836 template<class t_angle_type>
838 {
839 return Angle<t_angle_type>::atan(cast<fltp08>(sqrt(tan(roll) * tan(roll) + tan(pitch) * tan(pitch))));
840 }
841
842 template<class t_angle_type, uint01 t_dims, class t_type>
844 {
845 const Vector<2, t_type> xy_diff = ray.template as<2, t_type>();
846 return Angle<t_angle_type>::atan2(ray[Z], xy_diff.template magnitude<t_type>());
847 }
848
849 template<class t_angle_type, uint01 t_dims, class t_type>
851 {
852 return Angle<t_angle_type>::atan2(ray[Y], ray[X]);
853 }
854
855 template<class t_angle_type, uint01 t_dims, class t_type>
857 {
859 for (uint01 i = 0; i < t_dims; i++)
860 orient_vector[i] = Angle<t_angle_type>(angle_type, ray[i]);
861 return orient_vector;
862 }
863 template<bool t_normalized, uint01 t_dims, class t_angle_type>
864 static constexpr Vector<t_dims, fltp08> Orientation(AngleType angle_type, const Vector<t_dims, Angle<t_angle_type>>& ray)
865 {
866 Vector<t_dims, fltp08> orient_vector;
867 for (uint01 i = 0; i < t_dims; i++)
868 orient_vector[i] = ray[i].as(angle_type);
869 return orient_vector;
870 }
871 /**--------------------------------------------------------------------------------------------------
872 Fn: static Vector<3, Angle> AngleDefinitions::NormalToOrientation(const Vector<3, t_type>& normal,
873 const Angle& yaw = Angle(INTERNAL_ANGLE, 0))
874
875 Normal to orientation.
876
877 Author: Tyler Parke
878
879 Date: 2017-11-13
880
881 Parameters:
882 normal - The normal.
883 yaw - (Optional) The yaw.
884
885 Returns: A Vector&lt;3,Angle&gt;
886 *-----------------------------------------------------------------------------------------------**/
887 template<class t_angle_type, class t_type>
889 {
890 Angle<t_angle_type> pitch(RADIANS, (cast<fltp08>(asin((normal[Y] * sin(yaw) + normal[X] * cos(yaw))))));
892 if (::fabs(cos(pitch)) < 0.001)
893 roll = Angle<t_angle_type>(DEGREES, 0.0);
894 else if (::fabs(cos(yaw)) < 0.01)
895 roll = Angle<t_angle_type>(RADIANS, cast<fltp08>(-asin((cos(yaw) * sin(pitch) - normal[X]) / cos(pitch) * -sin(yaw))));
896 else
897 roll = Angle<t_angle_type>(RADIANS, cast<fltp08>(-asin((-normal[Y] + sin(yaw) * sin(pitch)) / (cos(pitch) * cos(yaw)))));
898 if (normal[Z] < 0)
899 roll = Angle<t_angle_type>(DEGREES, 180.0) - roll;
900 return Vector<3, Angle<t_angle_type>>(roll, pitch, yaw);
901 }
902
903 template<class t_angle_type>
905 {
906 fltp08 suggested_pitch_value = angle[PITCH].template as<DEGREES>();
907 fltp08 our_pitch_value = reference[PITCH].template as<DEGREES>();
908
909 fltp08 suggested_yaw_value = angle[YAW].template as<DEGREES>();
910 fltp08 our_yaw_value = reference[YAW].template as<DEGREES>();
911
912 fltp08 suggested_roll_value = angle[ROLL].template as<DEGREES>();
913 fltp08 our_roll_value = reference[ROLL].template as<DEGREES>();
914
915 if (suggested_pitch_value - our_pitch_value > 180)
916 our_pitch_value += 360;
917 else if (our_pitch_value - suggested_pitch_value > 180)
918 suggested_pitch_value += 360;
919
920 if (suggested_yaw_value - our_yaw_value > 180)
921 our_yaw_value += 360;
922 else if (our_yaw_value - suggested_yaw_value > 180)
923 suggested_yaw_value += 360;
924
925 if (suggested_roll_value - our_roll_value > 180)
926 our_roll_value += 360;
927 else if (our_roll_value - suggested_roll_value > 180)
928 suggested_roll_value += 360;
929
930 bool flip = ::abs(suggested_roll_value - our_roll_value) >= 90.0f && ::abs(suggested_yaw_value - our_yaw_value) >= 90.0f;
931 if (flip)
932 {
933 angle[ROLL] = Angle<fltp08>(DEGREES, angle[ROLL].template as<DEGREES>() - 180);
934 angle[YAW] = Angle<fltp08>(DEGREES, angle[YAW].template as<DEGREES>() - 180);
935 }
936 return angle;
937 }
938
939 public:
940 /**--------------------------------------------------------------------------------------------------
941 Fn: static const fltp08* AngleDefinitions::CalcIndexSin();
942
943 Calculates the index sine.
944
945 Author: Tyler Parke
946
947 Date: 2017-11-13
948
949 Returns: Null if it fails, else the calculated index sine.
950 *-----------------------------------------------------------------------------------------------**/
951 static const fltp08* CalcIndexSin();
952 };
953
954 template<uint01 t_dims, class t_angle_type>
959
960 template<uint01 t_dims, class t_angle_type>
965};
966
#define NDEVR_BASE_API
Definition DLLInfo.h:78
Logic for converting between Euler angles and basic rotations or normals.
Definition AngleFunctions.h:777
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))
Definition AngleFunctions.h:888
static Vector< 3, Angle< t_angle_type > > NormalizeOrientation(Vector< 3, Angle< t_angle_type > > angle, const Vector< 3, Angle< t_angle_type > > &reference)
Definition AngleFunctions.h:904
static constexpr Angle< t_angle_type > Heading(const Vector< t_dims, t_type > ray)
Definition AngleFunctions.h:850
static constexpr Vector< t_dims, fltp08 > Orientation(AngleType angle_type, const Vector< t_dims, Angle< t_angle_type > > &ray)
Definition AngleFunctions.h:864
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)
Definition AngleFunctions.h:815
static Angle< t_angle_type > Inclination(const Angle< t_angle_type > &roll, const Angle< t_angle_type > &pitch)
Definition AngleFunctions.h:837
static constexpr Vector< t_dims, Angle< t_angle_type > > Orientation(AngleType angle_type, const Vector< t_dims, t_type > &ray)
Definition AngleFunctions.h:856
static constexpr Angle< t_angle_type > Inclination(const Vector< t_dims, t_type > ray)
Definition AngleFunctions.h:843
Stores an angle in an optimized format.
Definition StringStream.h:352
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr t_type magnitudeSquared() const
Definition Vector.hpp:458
Definition ACIColor.h:37
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type tan(const Angle< t_type > &angle)
Definition AngleFunctions.h:182
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:1096
@ ROLL
Definition Angle.h:51
@ YAW
Definition Angle.h:53
@ PITCH
Definition Angle.h:52
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))
Definition AngleFunctions.h:955
@ angle_b
Definition Triangle.hpp:61
@ angle_a
Definition Triangle.hpp:60
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
AngleType
The possible units that can be used by the angle class. These are returned and used for real world an...
Definition Angle.h:64
@ RADIANS
Definition Angle.h:65
@ DEGREES
Definition Angle.h:66
@ INTERNAL_ANGLE
Definition Angle.h:67
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type cos(const Angle< t_type > &angle)
Definition AngleFunctions.h:154
constexpr Vector< t_dims, Angle< t_new_type > > ToTypeAngle(const Vector< t_dims, Angle< t_angle_type > > &old)
Definition AngleFunctions.h:758
NDEVR_BASE_API const fltp08 *const s_index_sin
Definition AngleFunctions.cpp:35
t_type sqrt(const t_type &value)
Definition VectorFunctions.hpp:1309
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:109
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type sin(const Angle< t_type > &angle)
Definition AngleFunctions.h:113
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)
Definition AngleFunctions.h:734
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ Z
Definition BaseValues.hpp:204
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181