I have two 3-D points.
Example:
float[] point1 = new float[3] {1.3919023, 6.12837912, 10.391283};
float[] point2 = new float[3] {48.3818, 38.38182, 318.381823};
Anyone an idea for an algorithm to calculate the distance in float between the points?
Solution: The distance between two points using coordinates can be given as, d = √[(x2 x 2 − x1 x 1 )2 + (y2 y 2 − y1 y 1 )2], where (x1,y1 x 1 , y 1 ) and (x2,y2 x 2 , y 2 ) are the coordinates of the two points.
What is 2D Distance Formula? The 2D distance formula gives the shortest distance between two points in a two-dimensional plane. The formula says the distance between two points (x1,y1) ( x 1 , y 1 ) , and (x2,y2) ( x 2 , y 2 ) is D=√(x2−x1)2+(y2−y1)2 D = ( x 2 − x 1 ) 2 + ( y 2 − y 1 ) 2 .
What Is 3D Distance Formula? The 3d distance formula says, the distance between two points in the space A(x1, y1, z1) and B(x2, y2, z2) is given as: d=√(x2−x1)2+(y2−y1)2+(z2−z1)2.
To calculate the distance between two points in 3D in Python, use the math. dist() method.
The Euclidean distance between two 3D points is:
float deltaX = x1 - x0;
float deltaY = y1 - y0;
float deltaZ = z1 - z0;
float distance = (float) Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
And in N dimensions (untested and vulnerable to overflow):
float DistanceN(float[] first, float[] second) {
var sum = first.Select((x, i) => (x - second[i]) * (x - second[i])).Sum();
return Math.Sqrt(sum);
}
Edit: I much prefer the Zip
solution posted by dasblinkenlight below!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With