I have set of line segments (not lines), (A1, B1)
, (A2, B2)
, (A3, B3)
, where A
,B
are ending points of the line segment. Each A
and B
has (x,y)
coordinates.
QUESTION:
I need to know the shortest distance between point O
and line segments
as shown in the shown figure implemented in line of codes. The code I can really understand is either pseudo-code or Python.
CODE: I tried to solve the problem with this code, unfortunately, it does not work properly.
def dist(A, B, O):
A_ = complex(*A)
B_ = complex(*B)
O_= complex(*O)
OA = O_ - A_
OB = O_ - B_
return min(OA, OB)
# coordinates are given
A1, B1 = [1, 8], [6,4]
A2, B2 = [3,1], [5,2]
A3, B3 = [2,3], [2, 1]
O = [2, 5]
A = [A1, A2, A3]
B = [B1, B2, B3]
print [ dist(i, j, O) for i, j in zip(A, B)]
Thanks in advance.
Here is the answer. This code belongs to Malcolm Kesson, the source is here. I provided it before with just link itself and it was deleted by the moderator. I assume that the reason for that is because of not providing the code (as an answer).