'Doing elementary analytic geometry in pandas

We have two points in Cartesian space as origins and some other typical points. For typical points we are only interested in their distance from the origins: two numbers. so we want reach from df

d = {'origin1': [(1,0,0), (0,0,0)],
     'origin2': [(2,0,0), (0,0,1)],
     'point1': [(40,0,0), (0,0,20)],
     'point2': [(50,0,0), (0,0,25)],
     'point3': [(60,0,0), (0,0,30)]}

display(pd.DataFrame(data=d, index=[0, 1]))

to df

d = {'origin1': [(1,0,0), (0,0,0)],
     'origin2': [(2,0,0), (0,0,1)],
     'point1': [(39,38), (20,19)],
     'point2': [(49,48), (25,24)],
     'point3': [(59,58), (30,29)]}

display(pd.DataFrame(data=d, index=[0, 1]))

Of course here we chose simple number for simple distance to see the problem. in general case we should use Pythagorean distance formula.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source