-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicycle_utils.py
39 lines (36 loc) · 998 Bytes
/
unicycle_utils.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
import matplotlib.pyplot as plt
import numpy as np
def plotUnicycle(x,pltAx):
'''
Plot a unicyle of a 2D matplotlib (top view), with fix-size arrows featuring the wheels.
'''
sc, delta = 0.1, 0.1
a, b, th = x
c, s = np.cos(th), np.sin(th)
refs = [
pltAx.arrow(
a - sc / 2 * c - delta * s,
b - sc / 2 * s + delta * c,
c * sc,
s * sc,
head_width=0.05,
),
pltAx.arrow(
a - sc / 2 * c + delta * s,
b - sc / 2 * s - delta * c,
c * sc,
s * sc,
head_width=0.05,
),
]
return refs
def plotUnicycleSolution(xs, pltAx=None):
'''
Plot a sequence of unicyles by calling iterativelly plotUnicycle.
If need be, create the figure window.
'''
if pltAx is None:
f, pltAx = plt.subplots(1, 1, figsize=(6.4, 6.4))
for x in xs:
plotUnicycle(x, pltAx)
pltAx.axis([-2, 2.0, -2.0, 2.0])