aboutsummaryrefslogtreecommitdiff
path: root/src/modules/mathlib/math/generic
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-07-04 15:43:38 +0200
committerLorenz Meier <lm@inf.ethz.ch>2013-07-04 15:43:38 +0200
commitf42b3ecd962a355081d36a62924e8ae9ecc05639 (patch)
tree57f94b62191af19d6df448763de694ea0fc599d8 /src/modules/mathlib/math/generic
parent3686431231af3dbbc3ca65417e9d1ca2dcd9d1de (diff)
downloadpx4-firmware-f42b3ecd962a355081d36a62924e8ae9ecc05639.tar.gz
px4-firmware-f42b3ecd962a355081d36a62924e8ae9ecc05639.tar.bz2
px4-firmware-f42b3ecd962a355081d36a62924e8ae9ecc05639.zip
Substantial improvements to math lib
Diffstat (limited to 'src/modules/mathlib/math/generic')
-rw-r--r--src/modules/mathlib/math/generic/Vector.hpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/modules/mathlib/math/generic/Vector.hpp b/src/modules/mathlib/math/generic/Vector.hpp
index 1a7363779..8cfdc676d 100644
--- a/src/modules/mathlib/math/generic/Vector.hpp
+++ b/src/modules/mathlib/math/generic/Vector.hpp
@@ -184,8 +184,17 @@ public:
return result;
}
+ inline Vector operator-(void) const {
+ Vector result(getRows());
+
+ for (size_t i = 0; i < getRows(); i++) {
+ result(i) = -((*this)(i));
+ }
+
+ return result;
+ }
// other functions
- inline float dot(const Vector &right) {
+ inline float dot(const Vector &right) const {
float result = 0;
for (size_t i = 0; i < getRows(); i++) {
@@ -194,12 +203,21 @@ public:
return result;
}
- inline float norm() {
+ inline float norm() const {
return sqrtf(dot(*this));
}
- inline Vector unit() {
+ inline float length() const {
+ return norm();
+ }
+ inline Vector unit() const {
return (*this) / norm();
}
+ inline Vector normalized() const {
+ return unit();
+ }
+ inline void normalize() {
+ (*this) = (*this) / norm();
+ }
inline static Vector zero(size_t rows) {
Vector result(rows);
// calloc returns zeroed memory