You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
d = np.abs(np.einsum("ij,ij->i",r,v)) / norm # Shape: (n_lines,), Compute: d = |(x1-x0)*(y2-y1)-(y1-y0)*(x1-x0)|/sqrt((x2-x1)**2 + (y2-y1)**2)
1113
1113
return d
1114
-
print(distance(P0, P1, p))
1114
+
print(distance_faster(P0, P1, p))
1115
1115
1116
1116
##--------------- OR ---------------##
1117
-
def distance(P0, P1, p):
1117
+
def distance_slower(P0, P1, p):
1118
1118
T = P1 - P0
1119
1119
L = (T**2).sum(axis=1)
1120
1120
U = -((P0[:,0]-p[...,0])*T[:,0] + (P0[:,1]-p[...,1])*T[:,1]) / L
1121
1121
U = U.reshape(len(U),1)
1122
1122
D = P0 + U*T - p
1123
1123
return np.sqrt((D**2).sum(axis=1))
1124
-
print(distance(P0, P1, p))
1124
+
print(distance_slower(P0, P1, p))
1125
1125
1126
1126
< q79
1127
1127
Consider 2 sets of points P0,P1 describing lines (2d) and a set of points P, how to compute distance from each point j (P[j]) to each line i (P0[i],P1[i])? (★★★)
0 commit comments