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.
21 #include "pbd/cartesian.h"
26 PBD::spherical_to_cartesian (double azi, double ele, double len, double& x, double& y, double& z)
28 /* convert from cylindrical coordinates in degrees to cartesian */
30 static const double atorad = 2.0 * M_PI / 360.0 ;
36 x = len * cos (azi * atorad) * cos (ele * atorad);
37 y = len * sin (azi * atorad) * cos (ele * atorad);
38 z = len * sin (ele * atorad);
42 PBD::cartesian_to_spherical (double x, double y, double z, double& azimuth, double& elevation, double& length)
44 /* converts cartesian coordinates to cylindrical in degrees*/
46 double rho, theta, phi;
48 rho = sqrt (x*x + y*y + z*z);
49 //phi = acos (1.0 / rho);
52 /* XXX for now, clamp phi to zero */
57 azimuth = 180.0 - (180.0 * (theta / M_PI)); /* LHS is negative */
59 azimuth = 180.0 * (theta / M_PI);
63 elevation = 180.0 - (180.0 * (phi / M_PI)); /* LHS is negative */
65 elevation = 180.0 * (phi / M_PI);