-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_first.py
121 lines (74 loc) · 2.64 KB
/
test_first.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import json
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
import matplotlib as mpl
from importlib import reload
import json
from pprint import pprint as pp
with open('Parser/data_shapes.json') as json_data:
d = json.load(json_data)
json_data.close()
list_of_polys = []
for key, value in d.items():
list_of_polys.append(value)
colorvec = np.linspace(0.2, 0.3, len(list_of_polys))
#--------------------------------------------------
# Test the plot
#--------------------------------------------------
fig, ax = plt.subplots()
# Make the collection and add it to the plot.
coll = PolyCollection(list_of_polys,
array=colorvec,
cmap=mpl.cm.jet,
edgecolors='black')
ax.add_collection(coll)
ax.autoscale_view()
# Add a colorbar for the PolyCollection
fig.colorbar(coll, ax=ax)
plt.show()
#--------------------------------------------------
tt = np.array( [[-100, -100]] )
theta = np.pi/2
tt = np.array( [[np.cos(theta) , np.sin(theta)],
[ -np.sin(theta) , np.cos(theta)]] )
def rotate(poly, theta=np.pi/2):
tt = np.array( [[ np.cos(theta) , np.sin(theta)],
[ -np.sin(theta) , np.cos(theta)]] )
return np.matmul(poly, tt)
Mat_translation = np.array(
[[ 1 , 0 , -100 ],
[ 0 , 1 , -100 ],
[ 0 , 0 , 1 ]]
)
new_list_of_polys = map(lambda x: x , list_of_polys)
np.concatenate([x, np.ones((x.shape[0],1))] ,axis=1)
fig, ax = plt.subplots()
# Make the collection and add it to the plot.
coll = PolyCollection(new_list_of_polys, array=colorvec, cmap=mpl.cm.jet, edgecolors='black')
ax.add_collection(coll)
ax.autoscale_view()
ax.set_aspect('equal', 'box')
fig.colorbar(coll, ax=ax)
plt.show()
angles = np.linspace(0, np.pi*2, 8 )
angles = np.linspace(0, np.pi, 20)
list_of_transformed_polylists = [ map(lambda x: rotate(x, a), new_list_of_polys) for a in angles]
fig, ax = plt.subplots()
# Make the collection and add it to the plot.
coll = PolyCollection(new_list_of_polys, array=colorvec, cmap=mpl.cm.jet, edgecolors='black')
ax.add_collection(coll)
for transformed in list_of_transformed_polylists:
coll = PolyCollection(transformed, array=colorvec,
cmap=mpl.cm.jet,
edgecolors='black')
ax.add_collection(coll)
ax.autoscale_view()
ax.set_aspect('equal', 'box')
# Add a colorbar for the PolyCollection
fig.colorbar(coll, ax=ax)
plt.show()
# In the future, use
# https://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations
# and
# https://en.wikipedia.org/wiki/Translation_(geometry)