convert(polarCoordinates:toRectangularCoordinates:)
Converts double-precision polar coordinates to rectangular coordinates.
Declaration
static func convert<U, V>(polarCoordinates: U, toRectangularCoordinates rectangularCoordinates: inout V) where U : AccelerateBuffer, V : AccelerateMutableBuffer, U.Element == Double, V.Element == DoubleParameters
- polarCoordinates:
The source polar coordinates.
- rectangularCoordinates:
On output, the rectangular coordinates.
Discussion
The function calls the underlying vDSP_rectD 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]
let rectangularCoordinates = [Double](unsafeUninitializedCapacity: 2) {
buffer,initializedCount in
vDSP.convert(
polarCoordinates: polarCoordinates,
toRectangularCoordinates: &buffer
)
initializedCount = 2
}
// Prints "[5.0, 5.0]".
print(rectangularCoordinates)