Contents

polarToRectangular(_:)

Returns single-precision rectangular coordinates converted from polar coordinates.

Declaration

static func polarToRectangular<U>(_ polarCoordinates: U) -> [Float] where U : AccelerateBuffer, U.Element == Float

Parameters

  • polarCoordinates:

    The source polar coordinates.

Discussion

The function calls the underlying vDSP_rect function to convert the input angle-radius pairs to Cartesian x-y pairs.

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].map { Float($0) }

    let rectangularCoordinates = vDSP.polarToRectangular(polarCoordinates)
    
    // Prints "[5.0, 5.0]".
    print(rectangularCoordinates)

See Also

Converting polar coordinates to rectangular coordinates