Converts double-precision rectangular coordinates to polar coordinates, using the specified stride.
SDKs
- iOS 4.0+
- macOS 10.4+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Accelerate
Declaration
void vDSP_polarD(const double *__A, v DSP _Stride __IA, double *__C, v DSP _Stride __IC, v DSP _Length __N);
Parameters
__A
Double-precision real input vector.
__IA
Stride for
A
, must be even.__C
Double-precision 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)
{
x = A[n*IA+0];
y = A[n*IA+1];
C[n*IC+0] = sqrt(x**2 + y**2);
C[n*IC+1] = atan2(y, x);
}
Converts rectangular coordinates to polar coordinates. Vector A
defines Cartesian (x, y) pairs. The function writes polar (rho, theta) pairs, where rho is the radius and theta is the angle in the range [-pi, pi]
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 a single pair of rectangular coordinates to their polar equivalent.
let x = 5.0
let y = 5.0
let rectangularCoordinates = [x, y]
var polarCoordinates: [Double] = [0, 0]
let stride = vDSP_Stride(2)
let n = vDSP_Length(1)
vDSP_polarD(rectangularCoordinates, stride,
&polarCoordinates, stride,
n)
let radius = polarCoordinates[0]
let angle = Measurement(value: polarCoordinates[1],
unit: UnitAngle.radians)
.converted(to: UnitAngle.degrees)
.value
On return, radius
is 7
, and angle
is 45
.
This function performs the inverse operation of v
, which converts polar to rectangular coordinates.