Ardour  9.0-pre0-582-g084a23a80d
cartesian.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2015 Paul Davis <paul@linuxaudiosystems.com>
3  *
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.
8  *
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.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include <cfloat>
22 #include <cmath>
23 
24 #include "pbd/libpbd_visibility.h"
25 
26 namespace PBD {
27 
28 LIBPBD_API void spherical_to_cartesian (double azi, double ele, double len, double& x, double& y, double& z);
29 LIBPBD_API void cartesian_to_spherical (double x, double y, double z, double& azi, double& ele, double& len);
30 
31 struct AngularVector;
32 
34  double x;
35  double y;
36  double z;
37 
38  CartesianVector () : x(0.0), y(0.0), z(0.0) {}
39  CartesianVector (double xp, double yp, double zp = 0.0) : x(xp), y(yp), z(zp) {}
40 
41  CartesianVector& translate (CartesianVector& other, double xtranslate, double ytranslate, double ztranslate = 0.0) {
42  other.x += xtranslate;
43  other.y += ytranslate;
44  other.z += ztranslate;
45  return other;
46  }
47 
48  CartesianVector& scale (CartesianVector& other, double xscale, double yscale, double zscale = 1.0) {
49  other.x *= xscale;
50  other.y *= yscale;
51  other.z *= zscale;
52  return other;
53  }
54 
55  inline void angular (AngularVector& a) const;
56 };
57 
59  double azi;
60  double ele;
61  double length;
62 
63  AngularVector () : azi(0.0), ele(0.0), length (0.0) {}
64  AngularVector (double a, double e, double l = 1.0) : azi(a), ele(e), length (l) {}
65 
66  AngularVector operator- (const AngularVector& other) const {
67  AngularVector r;
68  r.azi = azi - other.azi;
69  r.ele = ele - other.ele;
70  r.length = length - other.length;
71  return r;
72  }
73 
74  AngularVector operator+ (const AngularVector& other) const {
75  AngularVector r;
76  r.azi = azi + other.azi;
77  r.ele = ele + other.ele;
78  r.length = length + other.length;
79  return r;
80  }
81 
82  bool operator== (const AngularVector& other) const {
83  return fabs (azi - other.azi) <= FLT_EPSILON &&
84  fabs (ele - other.ele) <= FLT_EPSILON &&
85  fabs (length - other.length) <= FLT_EPSILON;
86  }
87 
88  bool operator!= (const AngularVector& other) const {
89  return fabs (azi - other.azi) > FLT_EPSILON ||
90  fabs (ele - other.ele) > FLT_EPSILON ||
91  fabs (length - other.length) > FLT_EPSILON;
92  }
93 
94  void cartesian (CartesianVector& c) const {
95  spherical_to_cartesian (azi, ele, length, c.x, c.y, c.z);
96  }
97 };
98 
99 inline void CartesianVector::angular (AngularVector& a) const {
100  cartesian_to_spherical (x, y, z, a.azi, a.ele, a.length);
101 }
102 
103 }
104 
#define LIBPBD_API
PBD::PropertyDescriptor< timecnt_t > length
Definition: axis_view.h:42
void cartesian_to_spherical(double x, double y, double z, double &azi, double &ele, double &len)
void spherical_to_cartesian(double azi, double ele, double len, double &x, double &y, double &z)
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
void cartesian(CartesianVector &c) const
Definition: cartesian.h:94
AngularVector(double a, double e, double l=1.0)
Definition: cartesian.h:64
CartesianVector & translate(CartesianVector &other, double xtranslate, double ytranslate, double ztranslate=0.0)
Definition: cartesian.h:41
CartesianVector & scale(CartesianVector &other, double xscale, double yscale, double zscale=1.0)
Definition: cartesian.h:48
void angular(AngularVector &a) const
Definition: cartesian.h:99
CartesianVector(double xp, double yp, double zp=0.0)
Definition: cartesian.h:39