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
.trajpoly5(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")
33 text_p
+= "%+g%s" % (traj
.p
[4], "t^4")
35 text_p
+= "%+g%s" % (traj
.p
[5], "t^5")
36 text_p
= text_p
.replace("=+", "=")
40 text_v
+= "%g" % (traj
.v
[0])
42 text_v
+= "%+g%s" % (traj
.v
[1], "t")
44 text_v
+= "%+g%s" % (traj
.v
[2], "t^2")
46 text_v
+= "%+g%s" % (traj
.v
[3], "t^3")
48 text_v
+= "%+g%s" % (traj
.v
[4], "t^4")
49 text_v
= text_v
.replace("=+", "=")
53 text_a
+= "%g" % (traj
.a
[0])
55 text_a
+= "%+g%s" % (traj
.a
[1], "t")
57 text_a
+= "%+g%s" % (traj
.a
[2], "t^2")
59 text_a
+= "%+g%s" % (traj
.a
[3], "t^3")
60 text_a
= text_a
.replace("=+", "=")
62 plt
.figure("5 polynomial trajectory")
65 plt
.title("puintic polynomial trajectory")
66 plt
.ylabel("Position")
67 plt
.plot(data
, np
.array(traj
.pos(data
), copy
=False), "r-", label
=text_p
)
71 plt
.ylabel("Velocity")
72 plt
.plot(data
, np
.array(traj
.vel(data
), copy
=False), "b-", label
=text_v
)
76 plt
.ylabel("Acceleration")
77 plt
.plot(data
, np
.array(traj
.acc(data
), copy
=False), "g-", label
=text_a
)
81 plt
.savefig(os
.path
.join(base
, "trajectory_polynomial_5.png"))