Small fix in Artisan #3
This commit is contained in:
parent
5c5f62c582
commit
10adfebcc3
@ -568,13 +568,13 @@ Artisan
|
|||||||
def distance(P0, P1, p):
|
def distance(P0, P1, p):
|
||||||
T = P1 - P0
|
T = P1 - P0
|
||||||
L = (T**2).sum(axis=1)
|
L = (T**2).sum(axis=1)
|
||||||
U = -((P0[:,0]-p[0])*T[:,0] + (P0[:,1]-p[1])*T[:,1]) / L
|
U = -((P0[:,0]-p[...,0])*T[:,0] + (P0[:,1]-p[...,1])*T[:,1]) / L
|
||||||
U = U.reshape(len(U),1)
|
U = U.reshape(len(U),1)
|
||||||
D = P0 + U*T - p
|
D = P0 + U*T - p
|
||||||
return np.sqrt((D**2).sum(axis=1))
|
return np.sqrt((D**2).sum(axis=1))
|
||||||
|
|
||||||
P0 = np.random.uniform(-10,10,(100,2))
|
P0 = np.random.uniform(-10,10,(10,2))
|
||||||
P1 = np.random.uniform(-10,10,(100,2))
|
P1 = np.random.uniform(-10,10,(10,2))
|
||||||
p = np.random.uniform(-10,10,( 1,2))
|
p = np.random.uniform(-10,10,( 1,2))
|
||||||
print distance(P0, P1, p)
|
print distance(P0, P1, p)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user