-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathplot.py
83 lines (64 loc) · 2.17 KB
/
plot.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from matplotlib import pyplot
from open3d.cpu.pybind.visualization import draw_geometries
from matplotlib.patches import Rectangle
from utils import *
# scatter 3d points in a 2d image
def plot3D(x, y, z):
fig = pyplot.figure()
ax = fig.add_subplot(111, projection='3d')
# change the viewing angle
# change viewing angle
# ax.view_init(20, 270)
ax.scatter(x, y, z)
pyplot.show()
# scatter 2d points
# send x, z coordinates to see room from ceiling POV
def plot2D(x, y):
pyplot.scatter(x, y)
pyplot.show()
# scatter 2d points with rectangle on the plot
def plot2DWithBox(x, y, box):
bottomLeft = box[0]
topRight = box[2]
pyplot.scatter(x, y)
width = topRight[0] - bottomLeft[0]
height = topRight[1] - bottomLeft[1]
rect = Rectangle((bottomLeft[0], bottomLeft[1]), width, height,
fill=False,
color="purple",
linewidth=2)
pyplot.gca().add_patch(rect)
pyplot.show()
# scatter all points in 2d and color the clusters centers in different color,
# also colors the furthest center in a third color
def plot2DWithClustersCenters(x, y, centers):
pyplot.scatter(x, y)
centersX = []
centersY = []
avgX = 0
avgY = 0
for coordinates in centers:
avgX += coordinates[0]
avgY += coordinates[1]
centersX.append(coordinates[0])
centersY.append(coordinates[1])
pyplot.scatter(centersX, centersY)
avgX = float(avgX / len(centers))
avgY = float(avgY / len(centers))
pyplot.scatter(avgX, avgY)
print('Center of clusters centers: ', [avgX, avgY])
center = avgX, avgY
maxDistance = float('-inf')
furthestCenter = None
for point in centers:
distance = distanceBetween2Points(center, point)
if distance > maxDistance:
maxDistance = distance
furthestCenter = point
print('furthestPoint: ', furthestCenter)
pyplot.scatter(furthestCenter[0], furthestCenter[1])
pyplot.show()
# gets x, y, z coordinates and shows an interactive points cloud
def showCloud(x, y, z):
cloud = makeCloud(x, y, z)
draw_geometries([cloud]) # Visualize the point cloud