Main Content

sph2cartvec

Convert vector from spherical basis representation to cartesian representation

Description

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

Each column of vs is a vector in the spherical basis. The third dimension of vs can correspond to different spherical bases if az and el.

example

Examples

collapse all

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

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

   -0.7071
    0.7071
         0

Start with a two vectors in a spherical basis, one pointing along the local z-direction and the other pointing in the local y-direction.

Load the vectors pairs into two different pages. The pages correspond to points (az=20,el=2) and (az=90,el=35). Compute the components of these vectors with respect to the spherical bases at these points.

az = [20 90];
el = [2 35];

Set up page 1 with two vectors.

vs1 = [0 0 1];
vs2 = [0 1 0];
vs(:,:,1) = [vs1' vs2'];

Put the same vectors into page 2.

vs(:,:,2) = [vs1' vs2'];

Transform all vectors to the global cartesian coordinate frame.

vr = sph2cartvec(vs,az,el)
vr = 
vr(:,:,1) =

    0.9391   -0.0328
    0.3418   -0.0119
    0.0349    0.9994


vr(:,:,2) =

         0         0
    0.8192   -0.5736
    0.5736    0.8192

Input Arguments

collapse all

Vector in a spherical basis representation, specified as a real-valued 3-by-N matrix or a real-valued 3-by-N-by-M MATLAB array. N is the number of vectors to convert.

  • If vs is a 3-by-N matrix, each column represents a vector in one spherical basis defined by a scalar az and el arguments.

  • If vs is a 3-by-N-by-M MATLAB array, each column each column represents a vector in a spherical basis. Each column of vs contains the three components of a vector in the right-handed spherical basis. Each page of vs corresponds to different spherical bases. Both the az and el input arguments must be length-M row vectors. Each entry in the az and el vectors corresponds to a page in vs. The m-th page of vr is converted using the m-th values of az and el.

Units are in meters.

Example: [45.0;10;20.3]

Data Types: single | double

Azimuth angle, specified as a scalar or real-valued M-by-1 vector in the closed range [–180,180]. M is the number of azimuth angles and must match the size of el. 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, 0° azimuth angle and 0° elevation angle specify a point on the x-axis while an azimuth angle of –90° and an elevation angle of 0° specify a point on the y-axis. Angle units are in degrees.

Example: [10,45]

Data Types: single | double

Elevation angle specified as a scalar or real-valued M-by-1 vector in the closed range [–90,90]. M is the number of elevation angles and must match the size of az. To define the elevation angle of a point on the sphere, construct a vector from the origin to the point. The elevation angle is the angle from vector's orthogonal projection into the xy-plane to the vector itself. As examples, 0° elevation angle defines the equator of the sphere and ±90° elevation define the north and south poles, respectively. Angle units are in degrees.

Example: [2,-3]

Data Types: single | double

Output Arguments

collapse all

Cartesian basis representation of output vectors, returned as a real-valued 3-by-N matrix or real-valued MATLAB array. vr has the same size as vs. Each column of vr contains the three components of the vector in a cartesian coordinates.

More About

collapse all

Extended Capabilities

expand all

Version History

Introduced in R2013a

expand all