From 4bfd0ce717a258d23f64dbb95441a84e7e570ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Mon, 14 May 2018 18:00:38 +0000 Subject: [PATCH] Some 2d cartesian vector functions Former-commit-id: f5de4b53cee352d5c1866dfc0a771f462b50af7a --- qpms/vectors.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qpms/vectors.h b/qpms/vectors.h index dda691a..d1ecb0c 100644 --- a/qpms/vectors.h +++ b/qpms/vectors.h @@ -8,6 +8,27 @@ //static inline double vectors_h_sq(double x) {return x*x;} +static inline cart2_t cart2_add(const cart2_t a, const cart2_t b) { + cart2_t res = {a.x+b.x, a.y+b.y}; + return res; +} + +static inline cart2_t cart2_substract(const cart2_t a, const cart2_t b) { + cart2_t res = {a.x-b.x, a.y-b.y}; + return res; +} + +static inline cart2_t cart2_scale(const double c, const cart2_t v) { + cart2_t res = {c * v.x, c * v.y}; + return res; +} + +static inline double cart2norm(const cart2_t v) { + return sqrt(v.x*v.x + v.y*v.y); +} + + + static inline double cart3norm(const cart3_t v) { return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); }