Next: , Previous: , Up: Arithmetic   [Contents][Index]

### 17.8 Coordinate Transformations

: [theta, r] = cart2pol (x, y)
: [theta, r, z] = cart2pol (x, y, z)
: [theta, r] = cart2pol (C)
: [theta, r, z] = cart2pol (C)

Transform Cartesian coordinates to polar or cylindrical coordinates.

The inputs x, y (, and z) must be the same shape, or scalar. If called with a single matrix argument then each row of C represents the Cartesian coordinate pair (x, y) or triplet (x, y, z).

The outputs theta, r (, and z) match the shape of the inputs. For a matrix input C the outputs will be column vectors with rows corresponding to the rows of the input matrix.

theta describes the angle relative to the positive x-axis measured in the xy-plane.

r is the distance to the z-axis (0, 0, z).

z, if present, is unchanged by the transformation.

The coordinate transformation is computed using:

```theta = arctan (y / x)
r = sqrt (x^2 + y^2)
z = z
```

Note: For MATLAB compatibility, this function no longer returns a full coordinate matrix when called with a single return argument.

: [x, y] = pol2cart (theta, r)
: [x, y, z] = pol2cart (theta, r, z)
: [x, y] = pol2cart (P)
: [x, y, z] = pol2cart (P)

Transform polar or cylindrical coordinates to Cartesian coordinates.

The inputs theta, r, (and z) must be the same shape, or scalar. If called with a single matrix argument then each row of P represents the polar coordinate pair (theta, r) or the cylindrical triplet (theta, r, z).

The outputs x, y (, and z) match the shape of the inputs. For a matrix input P the outputs will be column vectors with rows corresponding to the rows of the input matrix.

theta describes the angle relative to the positive x-axis measured in the xy-plane.

r is the distance to the z-axis (0, 0, z).

z, if present, is unchanged by the transformation.

The coordinate transformation is computed using:

```x = r * cos (theta)
y = r * sin (theta)
z = z
```

Note: For MATLAB compatibility, this function no longer returns a full coordinate matrix when called with a single return argument.

: [theta, phi, r] = cart2sph (x, y, z)
: [theta, phi, r] = cart2sph (C)

Transform Cartesian coordinates to spherical coordinates.

The inputs x, y, and z must be the same shape, or scalar. If called with a single matrix argument then each row of C must represent a Cartesian coordinate triplet (x, y, z).

The outputs theta, phi, r match the shape of the inputs. For a matrix input C the outputs will be column vectors with rows corresponding to the rows of the input matrix.

theta describes the azimuth angle relative to the positive x-axis measured in the xy-plane.

phi is the elevation angle measured relative to the xy-plane.

r is the distance to the origin (0, 0, 0).

The coordinate transformation is computed using:

```theta = arctan (y / x)
phi = arctan (z / sqrt (x^2 + y^2))
r = sqrt (x^2 + y^2 + z^2)
```

Note: For MATLAB compatibility, this function no longer returns a full coordinate matrix when called with a single return argument.

: [x, y, z] = sph2cart (theta, phi, r)
: [x, y, z] = sph2cart (S)

Transform spherical coordinates to Cartesian coordinates.

The inputs theta, phi, and r must be the same shape, or scalar. If called with a single matrix argument then each row of S must represent a spherical coordinate triplet (theta, phi, r).

The outputs x, y, z match the shape of the inputs. For a matrix input S the outputs are column vectors with rows corresponding to the rows of the input matrix.

theta describes the azimuth angle relative to the positive x-axis measured in the xy-plane.

phi is the elevation angle measured relative to the xy-plane.

r is the distance to the origin (0, 0, 0).

The coordinate transformation is computed using:

```x = r * cos (phi) * cos (theta)
y = r * cos (phi) * sin (theta)
z = r * sin (phi)
```

Note: For MATLAB compatibility, this function no longer returns a full coordinate matrix when called with a single return argument.