convert(rectangularCoordinates:toPolarCoordinates:)
Converts single-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 == Float, V.Element == FloatParameters
- rectangularCoordinates:
The source rectangular coordinates.
- polarCoordinates:
On output, the polar coordinates.
Discussion
The function calls the underlying vDSP_polarD 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 = [ 5.0, 5.0 ]
let polarCoordinates = [Double](unsafeUninitializedCapacity: 2) {
buffer,initializedCount in
vDSP.convert(
rectangularCoordinates: rectangularCoordinates,
toPolarCoordinates: &buffer
)
initializedCount = 2
}
let radius = polarCoordinates[0]
let angle = Measurement(value: polarCoordinates[1],
unit: UnitAngle.radians)
.converted(to: UnitAngle.degrees)
.value
// Prints "7.07 45.0".
print(radius, angle)