12 theta, tx, ty = sp.symbols(
"theta t_x t_y")
15 [[sp.cos(theta), -sp.sin(theta)], [sp.sin(theta), sp.cos(theta)]]
19 def apply_to(self, point: Point, pivot: Point):
25 ax, ay, bx, by = sp.symbols(
"a_x a_y b_x b_y")
29 def cost_with(self, rbt: RigidBodyTransform, pivot: Point):
30 v = rbt.apply_to(self.
a, pivot) - self.
b - pivot
31 return v[0] ** 2 + v[1] ** 2
35 cx, cy = sp.symbols(
"c_x c_y")
36 return Point([cx, cy])
42 .replace(
"theta",
"\\theta")
43 .replace(
"cos",
"\\cos")
44 .replace(
"sin",
"\\sin")
45 .replace(
"a_x - c_x",
"a'_x")
46 .replace(
"a_y - c_y",
"a'_y")
47 .replace(
"(a'_x)",
"a'_x")
48 .replace(
"(a'_y)",
"a'_y")
49 .replace(
"c_x",
"\\bar{a}_x")
50 .replace(
"c_y",
"\\bar{a}_y")
59cost = pair.cost_with(rbt, pivot)
61print(
"cost function:")
62print(sp.simplify(cost))
66dLdt_x = sp.diff(cost, rbt.translation[0])
70(t_x_opt,) = list(sp.linsolve([dLdt_x], rbt.translation[0]))[0]
71print(
"dL/dt_x = 0 when t_x = ")
74assert sp.simplify(dLdt_x.subs(rbt.translation[0], t_x_opt)) == 0
77dLdt_y = sp.diff(cost, rbt.translation[1])
81(t_y_opt,) = list(sp.linsolve([dLdt_y], rbt.translation[1]))[0]
82print(
"dL/dt_y = 0 when t_y = ")
85assert sp.simplify(dLdt_y.subs(rbt.translation[1], t_y_opt)) == 0
88dLdtheta = sp.diff(cost, rbt.theta)
89print(
latexify(sp.simplify(dLdtheta)))
cost_with(self, RigidBodyTransform rbt, Point pivot)
apply_to(self, Point point, Point pivot)