Contenido principal

cart2sphvec

Convert vector from cartesian representation to spherical representation

Description

vs = cart2sphvec(vr,az,el) converts the components of a vector or set of vectors, vr, from their representation in a local cartesian coordinate system to a spherical basis representation contained in vs. A spherical basis representation is the set of components of a vector projected into a 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, el. 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 Cartesian coordinates pointing along the z-direction and located at 45° azimuth, 45° elevation. Compute its components with respect to the spherical basis at that point.

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

         0
    0.7071
    0.7071

Start with a two vectors in Cartesian coordinates, one pointing along the z-direction and the other pointing in the y-direction.

Load the vector 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.

vr1 = [0 0 1];
vr2 = [0 1 0];
vr = [vr1' vr2']
vr = 3×2

    0    0
    0    1
    1    0

Put the same vectors into page 2.

vr(:,:,2) = vr
vr = 
vr(:,:,1) =

     0     0
     0     1
     1     0


vr(:,:,2) =

     0     0
     0     1
     1     0

Compute the spherical representations.

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

         0    0.9397
    0.9994   -0.0119
    0.0349    0.3418


vs(:,:,2) =

         0         0
    0.8192   -0.5736
    0.5736    0.8192

Input Arguments

collapse all

Vectors in a cartesian 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 vr is a 3-by-N matrix, each column represents a vector in one spherical basis defined by a scalar az and el arguments.

  • If vr is a 3-by-N-by-M MATLAB array, each column each column represents a vector in a cartesian basis. Each column of vr contains the three components of a vector in the right-handed cartesian basis. Each page of vr 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 vr. The m-th page of vr is converted using the m-th values of az and el.

Example: [4.0;-3.5;6.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

Spherical basis representation of output vectors, returned as a real-valued 3-by-N matrix or real-valued MATLAB array. vs has the same size as vr. Each column of vs contains the three components of the vector in a right-handed (e^az,e^el,e^R) basis.

More About

collapse all

Extended Capabilities

expand all

Version History

Introduced in R2013a

expand all