2 Copyright (C) 2010 Paul Davis
4 This program 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 2 of the License, or
7 (at your option) any later version.
9 This program 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 this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __libpbd_cartesian_h__
20 #define __libpbd_cartesian_h__
25 #include "pbd/libpbd_visibility.h"
29 LIBPBD_API void spherical_to_cartesian (double azi, double ele, double len, double& x, double& y, double& z);
30 LIBPBD_API void cartesian_to_spherical (double x, double y, double z, double& azi, double& ele, double& len);
34 struct LIBPBD_API CartesianVector {
39 CartesianVector () : x(0.0), y(0.0), z(0.0) {}
40 CartesianVector (double xp, double yp, double zp = 0.0) : x(xp), y(yp), z(zp) {}
42 CartesianVector& translate (CartesianVector& other, double xtranslate, double ytranslate, double ztranslate = 0.0) {
43 other.x += xtranslate;
44 other.y += ytranslate;
45 other.z += ztranslate;
49 CartesianVector& scale (CartesianVector& other, double xscale, double yscale, double zscale = 1.0) {
56 inline void angular (AngularVector& a) const;
59 struct LIBPBD_API AngularVector {
64 AngularVector () : azi(0.0), ele(0.0), length (0.0) {}
65 AngularVector (double a, double e, double l = 1.0) : azi(a), ele(e), length (l) {}
67 AngularVector operator- (const AngularVector& other) const {
69 r.azi = azi - other.azi;
70 r.ele = ele - other.ele;
71 r.length = length - other.length;
75 AngularVector operator+ (const AngularVector& other) const {
77 r.azi = azi + other.azi;
78 r.ele = ele + other.ele;
79 r.length = length + other.length;
83 bool operator== (const AngularVector& other) const {
84 return fabs (azi - other.azi) <= FLT_EPSILON &&
85 fabs (ele - other.ele) <= FLT_EPSILON &&
86 fabs (length - other.length) <= FLT_EPSILON;
89 bool operator!= (const AngularVector& other) const {
90 return fabs (azi - other.azi) > FLT_EPSILON ||
91 fabs (ele - other.ele) > FLT_EPSILON ||
92 fabs (length - other.length) > FLT_EPSILON;
95 void cartesian (CartesianVector& c) const {
96 spherical_to_cartesian (azi, ele, length, c.x, c.y, c.z);
100 inline void CartesianVector::angular (AngularVector& a) const {
101 cartesian_to_spherical (x, y, z, a.azi, a.ele, a.length);
106 #endif /* __libpbd_cartesian_h__ */