vDSP_distancesqD
Calculates the double-precision distance squared between two points in n-dimensional space.
Declaration
extern void vDSP_distancesqD(const double *__A, vDSP_Stride __IA, const double *__B, vDSP_Stride __IB, double *__C, vDSP_Length __N);Parameters
- __A:
An array that contains the coordinates of the first point.
- __IA:
The distance between the elements in the input vector
A. - __B:
An array that contains the coordinates of the second point.
- __IB:
The distance between the elements in the input vector
B. - __C:
On output, the square of the Euclidean distance between the two points.
- __N:
The number of elements to process.
Discussion
This function calculates the sum of squares of the differences of corresponding elements of vectors A and B, using the following operation:
C[0] = sum((A[n] - B[n]) ** 2, 0 <= n < N); For example, the following code calculates the distance squared between the two four-dimensional points pointA and pointB:
let stride = 1
let pointA: [Double] = [-1, 0, -2, 1]
let pointB: [Double] = [ 2, 1, 4, 3]
var distanceSquared = Double()
vDSP_distancesqD(pointA, stride,
pointB, stride,
&distanceSquared,
vDSP_Length(pointA.count))
print("distance²", distanceSquared) // Prints "distance² 50.0".