I am trying to write a code that moves a cylinder inside another (a prismatic joint). Manipulate is very slow and I suspect that this is because the position of the movable part is being computed and rendered everytime. I know you can do this with Dynamic but I haven't really learn how to use this properly. Could someone give me some help? Here is the simple code I use:
cylJoints[R_, r_, {z1_, z2_}] :=
Module[{b, cyl, d},
b = BoundaryDiscretizeRegion[
RegionDifference[Cylinder[{{0, 0, z1}, {0, 0, z2}}, R],
Cylinder[{{0, 0, z1}, {0, 0, z2}}, r]],
BaseStyle -> {Opacity[0.3]}];
d = (z2 - z1)/3;
cyl = Cylinder[{{0, 0, z1 - d}, {0, 0, z2 + d}}, r];
Manipulate[
Show[b, Graphics3D@Translate[cyl, {0, 0, t*d}]], {t, -1, 1}]];
cylJoints[6, 3, {-5, 5}]