Function

vDSP_rectD(_:_:_:_:_:)

Converts double-precision polar coordinates to rectangular coordinates, using the specified stride.

Declaration

func vDSP_rectD(_ __A: UnsafePointer<Double>, _ __IA: vDSP_Stride, _ __C: UnsafeMutablePointer<Double>, _ __IC: vDSP_Stride, _ __N: vDSP_Length)

Parameters

__A

Double-precision real input vector.

__IA

Stride for A, must be even.

__C

Double-precision real output vector.

__IC

Stride for C, must be even.

__N

Number of ordered pairs processed.

Discussion

This performs the following operation:

for (n = 0; n < N; ++n)
{
    r     = A[n*IA+0];
    theta = A[n*IA+1];
    C[n*IC+0] = r * cos(theta);
    C[n*IC+1] = r * sin(theta);
}

Converts polar coordinates to rectangular coordinates. Vector A defines polar (rho, theta) pairs, where rho is the radius and theta is the angle in the range [-pi, pi]. The function writes Cartesian (x, y) pairs to vector C. N specifies the number of coordinate pairs in A and C.

Coordinate pairs are adjacent elements in the array, regardless of stride; stride is the distance from one coordinate pair to the next.

The following code shows how to convert an angle-radius pair (with the angle specified in degress) to its rectangular equivalent.

let angle = Measurement(value: 45,
                        unit: UnitAngle.degrees)
    .converted(to: UnitAngle.radians)
    .value

let radius = sqrt(25.0 + 25.0)

let polarCoordinates = [radius, angle]

var rectangularCoordinates: [Double] = [0, 0]

let stride = vDSP_Stride(2)
let n = vDSP_Length(1)

vDSP_rectD(polarCoordinates, stride,
           &rectangularCoordinates, stride,
           n)

On return, rectangularCoordinates contains [5, 5].

This function performs the inverse operation of vDSP_polar, which converts rectangular to polar coordinates.

See Also

Single-Vector Polar-Rectangular Conversion

static func polarToRectangular<U>(U) -> [Double]

Returns double-precision polar coordinates converted to rectangular coordinates.

static func polarToRectangular<U>(U) -> [Float]

Returns single-precision polar coordinates converted to rectangular coordinates.

static func rectangularToPolar<U>(U) -> [Double]

Returns double-precision rectangular coordinates converted to polar coordinates.

static func rectangularToPolar<U>(U) -> [Float]

Returns single-precision rectangular coordinates converted to polar coordinates.

static func convert<U, V>(polarCoordinates: U, toRectangularCoordinates: inout V)

Converts double-precision polar coordinates to rectangular coordinates.

static func convert<U, V>(polarCoordinates: U, toRectangularCoordinates: inout V)

Converts single-precision polar coordinates to rectangular coordinates.

static func convert<U, V>(rectangularCoordinates: U, toPolarCoordinates: inout V)

Converts double-precision rectangular coordinates to polar coordinates.

static func convert<U, V>(rectangularCoordinates: U, toPolarCoordinates: inout V)

Converts single-precision rectangular coordinates to polar coordinates.

func vDSP_polar(UnsafePointer<Float>, vDSP_Stride, UnsafeMutablePointer<Float>, vDSP_Stride, vDSP_Length)

Converts single-precision rectangular coordinates to polar coordinates, using the specified stride.

func vDSP_polarD(UnsafePointer<Double>, vDSP_Stride, UnsafeMutablePointer<Double>, vDSP_Stride, vDSP_Length)

Converts double-precision rectangular coordinates to polar coordinates, using the specified stride.

func vDSP_rect(UnsafePointer<Float>, vDSP_Stride, UnsafeMutablePointer<Float>, vDSP_Stride, vDSP_Length)

Converts single-precision polar coordinates to rectangular coordinates, using the specified stride.