-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDistance.py
60 lines (48 loc) · 1.31 KB
/
Distance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 21 14:42:28 2018
@author: Ricardo Rivas
"""
import numpy as np
class ComputeDistance():
"""
This class computes the distance between points of a given domain
"""
@staticmethod
def __distEuclidian(p1, p2):
"""
Compute euclidian distance between two points p1, p2
Parameters
-----------
p1 : Tuple
Point 1 of a tuple of size 2 (x, y)
p2 : Tuple
Point 2 of a Tuple of size 2 (x, y)
"""
d = np.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)
return d
@staticmethod
def distanceMatrix(x):
"""
Compute r distance matrix
Parameters
-----------
x :
a list of tuples with position (x,y)
"""
N = len(x)
r = np.zeros((N,N))
for i in range(0,N):
for j in range(0,N):
r[i][j] = ComputeDistance.__distEuclidian(x[i], x[j])
return r
if __name__ == '__main__':
from Domain import DomainC
import matplotlib.pyplot as plt
L = 12
H = 9
ob = DomainC(L, H)
x = np.concatenate(ob.generateDomain())
r = ComputeDistance.distanceMatrix(x)
plt.imshow(r)