4 base
= os
.path
.dirname(__file__
)
5 path
= os
.path
.dirname(base
)
6 path
= os
.path
.dirname(path
)
7 sys
.path
.insert(0, path
)
10 import matplotlib
.pyplot
as plt
11 except Exception as e
:
15 import liba
# type: ignore
20 traj
= liba
.trajpoly3(t
[1] - t
[0], p
[0], p
[1], v
[0], v
[1])
21 data
= np
.arange(t
[0], t
[1], (t
[1] - t
[0]) / 1000)
25 text_p
+= "%g" % (traj
.p
[0])
27 text_p
+= "%+g%s" % (traj
.p
[1], "t")
29 text_p
+= "%+g%s" % (traj
.p
[2], "t^2")
31 text_p
+= "%+g%s" % (traj
.p
[3], "t^3")
32 text_p
= text_p
.replace("=+", "=")
36 text_v
+= "%g" % (traj
.v
[0])
38 text_v
+= "%+g%s" % (traj
.v
[1], "t")
40 text_v
+= "%+g%s" % (traj
.v
[2], "t^2")
41 text_v
= text_v
.replace("=+", "=")
45 text_a
+= "%g" % (traj
.a
[0])
47 text_a
+= "%+g%s" % (traj
.a
[1], "t")
48 text_a
= text_a
.replace("=+", "=")
50 plt
.figure("3 polynomial trajectory")
53 plt
.title("cubic polynomial trajectory")
54 plt
.ylabel("Position")
55 plt
.plot(data
, traj
.pos(data
), "r-", label
=text_p
)
59 plt
.ylabel("Velocity")
60 plt
.plot(data
, traj
.vel(data
), "b-", label
=text_v
)
64 plt
.ylabel("Acceleration")
65 plt
.plot(data
, traj
.acc(data
), "g-", label
=text_a
)
69 plt
.savefig(os
.path
.join(base
, "trajectory_polynomial_3.png"))