From 2b00af241e45adb0d1723afea1f694fc6acbb6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Mon, 14 May 2018 23:15:29 +0000 Subject: [PATCH] More 2d vectors features Former-commit-id: d260aeb125cbefaefcadd375c148ce06e8ba96be --- qpms/vectors.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/qpms/vectors.h b/qpms/vectors.h index d1ecb0c..f1f9047 100644 --- a/qpms/vectors.h +++ b/qpms/vectors.h @@ -23,11 +23,21 @@ static inline cart2_t cart2_scale(const double c, const cart2_t v) { return res; } +static inline double cart2_dot(const cart2_t a, const cart2_t b) { + return a.x * b.x + a.y * b.y; +} + static inline double cart2norm(const cart2_t v) { return sqrt(v.x*v.x + v.y*v.y); } - +static inline sph_t cart22sph(const cart2_t cart) { + sph_t sph; + sph.r = cart2norm(cart); + sph.theta = M_PI_2; + sph.phi = atan2(cart.y, cart.x); + return sph; +} static inline double cart3norm(const cart3_t v) { return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);