Contents

convert(rectangularCoordinates:toPolarCoordinates:)

Converts double-precision rectangular coordinates to polar coordinates.

Declaration

static func convert<U, V>(rectangularCoordinates: U, toPolarCoordinates polarCoordinates: inout V) where U : AccelerateBuffer, V : AccelerateMutableBuffer, U.Element == Double, V.Element == Double

Parameters

  • rectangularCoordinates:

    The source rectangular coordinates.

  • polarCoordinates:

    On output, the polar coordinates.

Discussion

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

The following code shows how to convert a set of Cartesian coordinates to its angle-radius pair (with the angle specified in degress) equivalent:

    let rectangularCoordinates: [Float] = [ 5.0, 5.0 ]

    let polarCoordinates = [Float](unsafeUninitializedCapacity: 2) {
        buffer,initializedCount in
        
        vDSP.convert(
            rectangularCoordinates: rectangularCoordinates,
            toPolarCoordinates: &buffer
        )
        
        initializedCount = 2
    }
    
    let radius = polarCoordinates[0]
    let angle = Measurement(value: Double(polarCoordinates[1]),
                            unit: UnitAngle.radians)
        .converted(to: UnitAngle.degrees)
        .value
    
    // Prints "7.07 45.0".
    print(radius, angle)

See Also

Converting rectangular coordinates to polar coordinates