-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistance.py
40 lines (37 loc) · 1.18 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
import numpy as np
import math
import shapely
def distancePointToShape(points, shape):
"""
Finds the average distance between all the points in a list and a shape to determine similarity.
:param points: list of 2d points
:param shape: list of 2d points
:return: float
"""
poly = shapely.Polygon(shape)
total_distance = 0
for i in points:
total_distance += poly.exterior.distance(shapely.Point(i))
return total_distance/len(points)
def distance(center, points):
"""
Calculates the distance between a center and points.
:param center: A nd point.
:param points: List of nd points.
:return: List of distances from center to each point in points.
"""
distances = []
for i in points:
distances.append(np.linalg.norm(i-center))
return distances
def distribution(distances):
"""
Creates a distribution from a list.
:param distances: List of distances.
:return: 2d List [number of distances left, cutoff]
"""
dist = []
for i in range(0, math.ceil(max(distances))+1):
distances = list(filter(lambda distance: distance > i, distances))
dist.append([len(distances)])
return dist