8 theta, tx, ty = sp.symbols(
'theta t_x t_y')
10 self.
rotation =
Matrix([[sp.cos(theta), -sp.sin(theta)], [sp.sin(theta), sp.cos(theta)]])
13 def apply_to(self, point: Point, pivot: Point):
18 ax, ay, bx, by = sp.symbols(
'a_x a_y b_x b_y')
22 def cost_with(self, rbt: RigidBodyTransform, pivot: Point):
23 v = rbt.apply_to(self.
a, pivot) - self.
b - pivot
24 return v[0] ** 2 + v[1] ** 2
27 cx, cy = sp.symbols(
'c_x c_y')
28 return Point([cx, cy])
32 .replace(
'theta',
'\\theta') \
33 .replace(
'cos',
'\\cos') \
34 .replace(
'sin',
'\\sin') \
35 .replace(
'a_x - c_x',
'a\'_x') \
36 .replace(
'a_y - c_y',
'a\'_y') \
37 .replace(
'(a\'_x)',
'a\'_x') \
38 .replace(
'(a\'_y)',
'a\'_y') \
39 .replace(
'c_x',
'\\bar{a}_x') \
40 .replace(
'c_y',
'\\bar{a}_y') \
48cost = pair.cost_with(rbt, pivot)
50print(
'cost function:')
51print(sp.simplify(cost))
55dLdt_x = sp.diff(cost, rbt.translation[0])
59t_x_opt, = list(sp.linsolve([dLdt_x], rbt.translation[0]))[0]
60print(
'dL/dt_x = 0 when t_x = ')
63assert(sp.simplify(dLdt_x.subs(rbt.translation[0], t_x_opt)) == 0)
66dLdt_y = sp.diff(cost, rbt.translation[1])
70t_y_opt, = list(sp.linsolve([dLdt_y], rbt.translation[1]))[0]
71print(
'dL/dt_y = 0 when t_y = ')
74assert(sp.simplify(dLdt_y.subs(rbt.translation[1], t_y_opt)) == 0)
77dLdtheta = sp.diff(cost, rbt.theta)
78print(
latexify(sp.simplify(dLdtheta)))
cost_with(self, RigidBodyTransform rbt, Point pivot)
apply_to(self, Point point, Point pivot)