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__
27 void azi_ele_to_cart (double azi, double ele, double& x, double& y, double& z);
28 void cart_to_azi_ele (double x, double y, double z, double& azi, double& ele);
32 struct CartesianVector {
37 CartesianVector () : x(0.0), y(0.0), z(0.0) {}
38 CartesianVector (double xp, double yp, double zp = 0.0) : x(xp), y(yp), z(zp) {}
40 CartesianVector& translate (CartesianVector& other, double xtranslate, double ytranslate, double ztranslate = 0.0) {
41 other.x += xtranslate;
42 other.y += ytranslate;
43 other.z += ztranslate;
47 CartesianVector& scale (CartesianVector& other, double xscale, double yscale, double zscale = 1.0) {
54 void angular (AngularVector&) const;
57 struct AngularVector {
62 AngularVector () : azi(0.0), ele(0.0), length (0.0) {}
63 AngularVector (double a, double e, double l = 1.0) : azi(a), ele(e), length (l) {}
65 AngularVector operator- (const AngularVector& other) const {
67 r.azi = azi - other.azi;
68 r.ele = ele - other.ele;
69 r.length = length - other.length;
73 AngularVector operator+ (const AngularVector& other) const {
75 r.azi = azi + other.azi;
76 r.ele = ele + other.ele;
77 r.length = length + other.length;
81 bool operator== (const AngularVector& other) const {
82 return fabs (azi - other.azi) <= FLT_EPSILON &&
83 fabs (ele - other.ele) <= FLT_EPSILON &&
84 fabs (length - other.length) <= FLT_EPSILON;
87 bool operator!= (const AngularVector& other) const {
88 return fabs (azi - other.azi) > FLT_EPSILON ||
89 fabs (ele - other.ele) > FLT_EPSILON ||
90 fabs (length - other.length) > FLT_EPSILON;
93 void cartesian (CartesianVector& c) const {
94 azi_ele_to_cart (azi, ele, c.x, c.y, c.z);
98 inline void CartesianVector::angular (AngularVector& a) const {
99 cart_to_azi_ele (x, y, z, a.azi, a.ele);
104 #endif /* __libpbd_cartesian_h__ */