Mercurial > ublox > ublox8
changeset 27:3b1e9a4cb41d
gnss: add ecef_subtract and ecef_magnitude helpers
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Tue, 14 Jan 2020 14:25:13 -0500 |
parents | f185303d238e |
children | b203d5f97b78 |
files | gnss.h |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gnss.h Tue Jan 14 11:14:50 2020 -0500 +++ b/gnss.h Tue Jan 14 14:25:13 2020 -0500 @@ -23,6 +23,8 @@ #ifndef __GNSS_H #define __GNSS_H +#include <math.h> + #include <jeffpc/types.h> struct ecef { @@ -31,4 +33,20 @@ double z; /* m */ }; +/* res = a - b */; +static inline void ecef_subtract(struct ecef *res, + const struct ecef *a, + const struct ecef *b) +{ + res->x = a->x - b->x; + res->y = a->y - b->y; + res->z = a->z - b->z; +} + +/* |a| */ +static inline double ecef_magnitude(const struct ecef *a) +{ + return sqrt(a->x * a->x + a->y * a->y + a->z * a->z); +} + #endif