0

i'm trying to write a python code to calculate the distance between two 3D points. Those points are listed as follows:

Timestamp, X, Y, Z, Distance

2613, 4.35715, 5.302030, -0.447308
2614, 7.88429, -8.401940, -0.484432
2615, 4.08796, 2.213850, -0.515359
2616, 4.35715, 5.302030, -0.447308
2617, 7.88429, -8.401940, -0.484432

i know the formula but I'm not sure how to list the column to run the formula for 3D point distance!

Ish
  • 17
  • 2
  • 7

2 Answers2

0

This is essentially the same question as How can the Euclidean distance be calculated with NumPy?

you can use numpy/scipy.linalg.norm

E.g.

scipy.lingalg.norm(2613-2614)
0

can you try this code and see if you can get some ideas to start:

# distance between 2 points in 3D

from math import pow, sqrt

from functools import reduce 

def calculate_dist(point1, point2):
    x, y, z = point1
    a, b, c = point2
    
    distance = sqrt(pow(a - x, 2) +
                    pow(b - y, 2) +
                    pow(c - z, 2)* 1.0) 
    return distance



point1 =  (2, 3, 4)  # tuple
point2 =  (1, 5, 7)

print(calculate_dist(point1, point2))


# reduce(calcuate_dist(oint1, point2))  # apply to your data
Daniel Hao
  • 4,922
  • 3
  • 10
  • 23