2 * This file is part of INAV.
4 * INAV is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * INAV is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with INAV. If not, see <http://www.gnu.org/licenses/>.
23 #include "common/maths.h"
41 void rotationMatrixFromAngles(fpMat3_t
* rmat
, const fp_angles_t
* angles
);
42 void rotationMatrixFromAxisAngle(fpMat3_t
* rmat
, const fpAxisAngle_t
* a
);
44 static inline void vectorZero(fpVector3_t
* v
)
51 static inline fpVector3_t
* rotationMatrixRotateVector(fpVector3_t
* result
, const fpVector3_t
* a
, const fpMat3_t
* rmat
)
55 r
.x
= rmat
->m
[0][0] * a
->x
+ rmat
->m
[1][0] * a
->y
+ rmat
->m
[2][0] * a
->z
;
56 r
.y
= rmat
->m
[0][1] * a
->x
+ rmat
->m
[1][1] * a
->y
+ rmat
->m
[2][1] * a
->z
;
57 r
.z
= rmat
->m
[0][2] * a
->x
+ rmat
->m
[1][2] * a
->y
+ rmat
->m
[2][2] * a
->z
;
63 static inline float vectorNormSquared(const fpVector3_t
* v
)
65 return sq(v
->x
) + sq(v
->y
) + sq(v
->z
);
68 static inline fpVector3_t
* vectorNormalize(fpVector3_t
* result
, const fpVector3_t
* v
)
70 float length
= fast_fsqrtf(vectorNormSquared(v
));
72 result
->x
= v
->x
/ length
;
73 result
->y
= v
->y
/ length
;
74 result
->z
= v
->z
/ length
;
84 static inline fpVector3_t
* vectorCrossProduct(fpVector3_t
* result
, const fpVector3_t
* a
, const fpVector3_t
* b
)
88 ab
.x
= a
->y
* b
->z
- a
->z
* b
->y
;
89 ab
.y
= a
->z
* b
->x
- a
->x
* b
->z
;
90 ab
.z
= a
->x
* b
->y
- a
->y
* b
->x
;
96 static inline fpVector3_t
* vectorAdd(fpVector3_t
* result
, const fpVector3_t
* a
, const fpVector3_t
* b
)
108 static inline fpVector3_t
* vectorScale(fpVector3_t
* result
, const fpVector3_t
* a
, const float b
)