-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraphics.py
37 lines (31 loc) · 1018 Bytes
/
graphics.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
from kinematics import Vector
import matplotlib.pyplot as plt
def chain_to_points(chain):
x = []
y = []
z = []
for transform in chain:
x += [transform.translation.x]
y += [transform.translation.y]
z += [transform.translation.z]
return (x, y, z)
def axis(ax, transform, size=1):
origin = transform.translation
x = transform + Vector(size, 0, 0)
y = transform + Vector(0, size, 0)
z = transform + Vector(0, 0, size)
r, = ax.plot([origin.x, x.x], [origin.y, x.y],
[origin.z, x.z], color="#ff0000")
g, = ax.plot([origin.x, y.x], [origin.y, y.y],
[origin.z, y.z], color="#00ff00")
b, = ax.plot([origin.x, z.x], [origin.y, z.y],
[origin.z, z.z], color="#0000ff")
return (r, g, b)
def figure(size):
half = size/2
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.set_xlim((-half, half))
ax.set_ylim((-half, half))
ax.set_zlim((0, size))
return (fig, ax)