-
Notifications
You must be signed in to change notification settings - Fork 24
/
mycart2sph.m
30 lines (28 loc) · 908 Bytes
/
mycart2sph.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [az,elev,r] = mycart2sph(x,y,z)
% 3D Cartesian to Spherical Coordinates
%
% [az,elev,r] = mycart2sph(x,y,z)
%
% Inputs:
% x x-coordinate
% y y-coordinate
% z z-coordinate
%
% Outputs:
% az Azimuth angle in radians, measured counterclockwise
% from the positive x axis (otherwise referred to as phi)
% elev Elevation angle in radians, from xy plane (otherwise
% referred to as theta)
% r Radius
%
% Notes:
% The MATLAB function cart2sph reverses phi and theta.
%
%**************************************************************************
% Author: E. A. P. Habets and M. R. P. Thomas
% Date: 27 July 2010
%**************************************************************************
hypotxy = hypot(x,y);
r = hypot(hypotxy,z);
elev = acos(z./r);
az = atan2(y,x);