-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualisation.py
More file actions
executable file
·57 lines (49 loc) · 1.9 KB
/
Copy pathvisualisation.py
File metadata and controls
executable file
·57 lines (49 loc) · 1.9 KB
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
#!/usr/bin/env python
from mpl_toolkits.mplot3d import axes3d
import matplotlib
import matplotlib.pyplot as plt
class Visualisation(object):
def __init__(self, window_size, use_quivers=False):
matplotlib.interactive(True)
fig = plt.figure(figsize=window_size)
self.makeAxes(fig)
self.ax.set_axis_off()
self.vis = None
self.vis_bb = None
self.use_quivers = use_quivers
def draw(self, boids, big_boids):
if self.vis is not None:
self.vis.remove()
if self.vis_bb is not None:
self.vis_bb.remove()
self.drawData(boids, big_boids)
plt.draw()
def makeAxes(self, fig):
pass
def drawData(self, boids, big_boids):
pass
class Visualisation2D(Visualisation):
def makeAxes(self, fig):
self.ax = fig.add_subplot(111)
self.ax.set_xlim( -1.5, 2.5 )
self.ax.set_ylim( -1.5, 2.5 )
def drawData(self, boids, big_boids):
if self.use_quivers:
self.vis = self.ax.quiver(boids.x, boids.y, boids.u, boids.v, scale=4.0)
self.vis_bb = self.ax.quiver(big_boids.x, big_boids.y, big_boids.u, big_boids.v,scale=2.0,color='r')
else:
self.vis = self.ax.scatter(boids.x, boids.y, c='b', marker='o')
self.vis_bb = self.ax.scatter(big_boids.x, big_boids.y, c='r', marker='^')
class Visualisation3D(Visualisation):
def makeAxes(self, fig):
self.ax = fig.add_subplot(111, projection='3d')
self.ax.set_xlim3d( -0.5, 1.5 )
self.ax.set_ylim3d( -0.5, 1.5 )
self.ax.set_zlim3d( -0.5, 1.5 )
def drawData(self, boids, big_boids):
if self.use_quivers:
self.vis = self.ax.quiver(boids.x, boids.y, boids.z, boids.u, boids.v, boids.w,length=0.02,arrow_length_ratio=1.0)
self.vis_bb = self.ax.quiver(big_boids.x, big_boids.y, big_boids.z, big_boids.u, big_boids.v, big_boids.w, length=0.04, arrow_length_ratio=1.0, color='r')
else:
self.vis = self.ax.scatter(boids.x, boids.y, boids.z, c='b', marker='o')
self.vis_bb = self.ax.scatter(big_boids.x, big_boids.y, big_boids.z, c='r', marker='^')