Transform Cartesian coordinates to spherical
Cartesian to Spherical Coordinates
Convert the Cartesian coordinates defined by corresponding entries in the matrices
z to spherical coordinates
r. These points correspond to the eight vertices of a cube.
x = [1 1 1 1; -1 -1 -1 -1]
x = 2×4 1 1 1 1 -1 -1 -1 -1
y = [1 1 -1 -1; 1 1 -1 -1]
y = 2×4 1 1 -1 -1 1 1 -1 -1
z = [1 -1 1 -1; 1 -1 1 -1]
z = 2×4 1 -1 1 -1 1 -1 1 -1
[az,el,r] = cart2sph(x,y,z)
az = 2×4 0.7854 0.7854 -0.7854 -0.7854 2.3562 2.3562 -2.3562 -2.3562
el = 2×4 0.6155 -0.6155 0.6155 -0.6155 0.6155 -0.6155 0.6155 -0.6155
r = 2×4 1.7321 1.7321 1.7321 1.7321 1.7321 1.7321 1.7321 1.7321
x,y,z — Cartesian coordinates
scalars | vectors | matrices | multidimensional arrays
Cartesian coordinates, specified as scalars, vectors, matrices,
or multidimensional arrays.
z must be the same size, or any of them can
azimuth — Azimuth angle
Azimuth angle, returned as an array.
azimuth is the counterclockwise angle
in the x-y
plane measured in radians from the positive
x-axis. The value of the angle
is in the range
elevation — Elevation angle
Elevation angle, returned as an array.
elevation is the elevation angle in
radians from the x-y plane. The value
of the angle is in the range
r — Radius
Radius, returned as an array.
r is the distance
from the origin to a point. The length units of
arbitrary, matching the units of the input arrays
The mapping from three-dimensional Cartesian coordinates to spherical coordinates is
azimuth = atan2(y,x) elevation = atan2(z,sqrt(x.^2 + y.^2)) r = sqrt(x.^2 + y.^2 + z.^2)
The notation for spherical coordinates is not standard. For
measured from the x-y plane. Notice that if
= 0, the point is in the x-y plane.
elevation = pi/2, then the point is on the positive z-axis.
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).