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.
20 #include "pbd/cartesian.h"
23 PBD::azi_ele_to_cart (double azi, double ele, double& x, double& y, double& z)
25 static const double atorad = 2.0 * M_PI / 360.0 ;
26 x = cos (azi * atorad) * cos (ele * atorad);
27 y = sin (azi * atorad) * cos (ele * atorad);
28 z = sin (ele * atorad);
32 PBD::cart_to_azi_ele (double x, double y, double z, double& azimuth, double& elevation)
34 /* converts cartesian coordinates to angular */
35 const double atorad = 2.0 * M_PI / 360.0;
36 double atan_y_per_x, atan_x_pl_y_per_z;
40 atan_y_per_x = M_PI / 2;
42 atan_y_per_x = atan(y / x);
45 azimuth = atan_y_per_x / atorad;
51 distance = sqrt (x*x + y*y);
54 atan_x_pl_y_per_z = 0.0;
56 atan_x_pl_y_per_z = atan (z/distance);
59 if (distance == 0.0) {
61 atan_x_pl_y_per_z = -M_PI/2.0;
63 atan_x_pl_y_per_z = M_PI/2.0;
67 elevation = atan_x_pl_y_per_z / atorad;
69 // distance = sqrtf (x*x + y*y + z*z);