Accelerating the pace of engineering and science

# sph2cartvec

Convert vector from spherical basis components to Cartesian components

## Description

example

vr = sph2cartvec(vs,az,el) converts the components of a vector or set of vectors, vs, from their spherical basis representation to their representation in a local Cartesian coordinate system. A spherical basis representation is the set of components of a vector projected into the right-handed spherical basis given by $\left({\stackrel{^}{e}}_{az},{\stackrel{^}{e}}_{el},{\stackrel{^}{e}}_{R}\right)$. The orientation of a spherical basis depends upon its location on the sphere as determined by azimuth, az, and elevation, el.

## Examples

expand all

### Cartesian Representation of Azimuthal Vector

Start with a vector in a spherical basis located at 45° azimuth, 45° elevation. The vector points along the azimuth direction. Compute its components with respect to Cartesian coordinates.

```vs = [1;0;0];
vr = sph2cartvec(vs,45,45)```
```vr =

-0.7071
0.7071
0```

## Input Arguments

expand all

### vs — Vector in spherical basis representation3-by-1 column vector | 3-by-N matrix

Vector in spherical basis representation specified as a 3-by-1 column vector or 3-by-N matrix. Each column of vs contains the three components of a vector in the right-handed spherical basis $\left({\stackrel{^}{e}}_{az},{\stackrel{^}{e}}_{el},{\stackrel{^}{e}}_{R}\right)$.

Example: [4.0; -3.5; 6.3]

Data Types: double
Complex Number Support: Yes

### az — Azimuth anglescalar in range [–180,180]

Azimuth angle specified as a scalar in the closed range [–180,180]. Angle units are in degrees. To define the azimuth angle of a point on a sphere, construct a vector from the origin to the point. The azimuth angle is the angle in the xy-plane from the positive x-axis to the vector's orthogonal projection into the xy-plane. As examples, zero azimuth angle and zero elevation angle specify a point on the x-axis while an azimuth angle of 90° and an elevation angle of zero specify a point on the y-axis.

Example: 45

Data Types: double

### el — Elevation anglescalar in range [–90,90]

Elevation angle specified as a scalar in the closed range [–90,90]. Angle units are in degrees. To define the elevation of a point on the sphere, construct a vector from the origin to the point. The elevation angle is the angle from its orthogonal projection into the xy-plane to the vector itself. As examples, zero elevation angle defines the equator of the sphere and ±90° elevation define the north and south poles, respectively.

Example: 30

Data Types: double

## Output Arguments

expand all

### vr — Vector in Cartesian representation3-by-1 column vector | 3-by-N matrix

Cartesian vector returned as a 3-by-1 column vector or 3-by-N matrix having the same dimensions as vs. Each column of vr contains the three components of the vector in the right-handed x,y,z basis.

expand all

### Spherical basis representation of vectors

The spherical basis is a set of three mutually orthogonal unit vectors $\left({\stackrel{^}{e}}_{az},{\stackrel{^}{e}}_{el},{\stackrel{^}{e}}_{R}\right)$ defined at a point on the sphere. The first unit vector points along lines of azimuth at constant radius and elevation. The second points along the lines of elevation at constant azimuth and radius. Both are tangent to the surface of the sphere. The third unit vector points radially outward.

The orientation of the basis changes from point to point on the sphere but is independent of R so as you move out along the radius, the basis orientation stays the same. The following figure illustrates the orientation of the spherical basis vectors as a function of azimuth and elevation:

For any point on the sphere specified by az and el, the basis vectors are given by:

Any vector can be written in terms of components in this basis as $v={v}_{az}{\stackrel{^}{e}}_{az}+{v}_{el}{\stackrel{^}{e}}_{el}+{v}_{R}{\stackrel{^}{e}}_{R}$. The transformations between spherical basis components and Cartesian components take the form

$\left[\begin{array}{c}{v}_{x}\\ {v}_{y}\\ {v}_{z}\end{array}\right]=\left[\begin{array}{ccc}-\mathrm{sin}\left(az\right)& -\mathrm{sin}\left(el\right)\mathrm{cos}\left(az\right)& \mathrm{cos}\left(el\right)\mathrm{cos}\left(az\right)\\ \mathrm{cos}\left(az\right)& -\mathrm{sin}\left(el\right)\mathrm{sin}\left(az\right)& \mathrm{cos}\left(el\right)\mathrm{sin}\left(az\right)\\ 0& \mathrm{cos}\left(el\right)& \mathrm{sin}\left(el\right)\end{array}\right]\left[\begin{array}{c}{v}_{az}\\ {v}_{el}\\ {v}_{R}\end{array}\right]$

.

and

$\left[\begin{array}{c}{v}_{az}\\ {v}_{el}\\ {v}_{R}\end{array}\right]=\left[\begin{array}{ccc}-\mathrm{sin}\left(az\right)& \mathrm{cos}\left(az\right)& 0\\ -\mathrm{sin}\left(el\right)\mathrm{cos}\left(az\right)& -\mathrm{sin}\left(el\right)\mathrm{sin}\left(az\right)& \mathrm{cos}\left(el\right)\\ \mathrm{cos}\left(el\right)\mathrm{cos}\left(az\right)& \mathrm{cos}\left(el\right)\mathrm{sin}\left(az\right)& \mathrm{sin}\left(el\right)\end{array}\right]\left[\begin{array}{c}{v}_{x}\\ {v}_{y}\\ {v}_{z}\end{array}\right]$.