Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
geometryfuncs.h@0:886118d8488d, 2012-04-26 (annotated)
- Committer:
- narshu
- Date:
- Thu Apr 26 19:34:16 2012 +0000
- Revision:
- 0:886118d8488d
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| narshu | 0:886118d8488d | 1 | #ifndef GEOMETRYFUNCS_H |
| narshu | 0:886118d8488d | 2 | #define GEOMETRYFUNCS_H |
| narshu | 0:886118d8488d | 3 | |
| narshu | 0:886118d8488d | 4 | #include <tvmet/Matrix.h> |
| narshu | 0:886118d8488d | 5 | |
| narshu | 0:886118d8488d | 6 | template <typename T> |
| narshu | 0:886118d8488d | 7 | Matrix <T, 2, 2> Rotmatrix(T theta) { |
| narshu | 0:886118d8488d | 8 | Matrix <T, 2, 2> outmatrix; |
| narshu | 0:886118d8488d | 9 | outmatrix = cos(theta), -sin(theta), |
| narshu | 0:886118d8488d | 10 | sin(theta), cos(theta); |
| narshu | 0:886118d8488d | 11 | return outmatrix; |
| narshu | 0:886118d8488d | 12 | } |
| narshu | 0:886118d8488d | 13 | |
| narshu | 0:886118d8488d | 14 | // rectifies angle to range -PI to PI |
| narshu | 0:886118d8488d | 15 | template <typename T> |
| narshu | 0:886118d8488d | 16 | T rectifyAng (T ang_in) { |
| narshu | 0:886118d8488d | 17 | ang_in -= (floor(ang_in/(2*PI)))*2*PI; |
| narshu | 0:886118d8488d | 18 | if (ang_in < -PI) { |
| narshu | 0:886118d8488d | 19 | ang_in += 2*PI; |
| narshu | 0:886118d8488d | 20 | } |
| narshu | 0:886118d8488d | 21 | if (ang_in > PI) { |
| narshu | 0:886118d8488d | 22 | ang_in -= 2*PI; |
| narshu | 0:886118d8488d | 23 | } |
| narshu | 0:886118d8488d | 24 | |
| narshu | 0:886118d8488d | 25 | return ang_in; |
| narshu | 0:886118d8488d | 26 | } |
| narshu | 0:886118d8488d | 27 | |
| narshu | 0:886118d8488d | 28 | #endif //GEOMETRYFUNCS_H |