cart2pol
Converts Cartesian coordinates to polar or cylindrical.
Category: Mathematics > Elementary Math
Syntax
[theta, rho] = cart2pol(x, y)
Converts 2-D Cartesian coordinates to polar coordinates.
[theta, rho, z] = cart2pol(x, y, z)
Converts 3-D Cartesian coordinates to cylindrical coordinates; z is passed through.
Description
The conversion is theta = atan2(y, x) and rho = sqrt(x.^2 + y.^2). The inverse is pol2cart. Note the order of the outputs: the angle comes first, then the radius.
With a single output, cart2pol(x, y) returns only theta.
Input arguments
x, y, z- Arrays of equal size (or scalars) with the Cartesian coordinates.
Output arguments
theta- Counterclockwise angle from the positive x-axis, in radians, in
[-pi, pi]. rho- Distance from the origin (or from the z-axis in 3-D).
z- Unchanged height (3-D form).
Example
Polar coordinates of (1, 1)
[theta, rho] = cart2pol(1, 1)
[theta, rho, z] = cart2pol(1, 1, 5)
Output
theta = 0.7854
rho = 1.4142
theta = 0.7854
rho = 1.4142
z = 5
Notes
MatLivre requires the coordinates as separate arguments. The MATLAB form that takes a single matrix with two or three columns is not supported.