# Manipulate - mechanics

I have a simple manipulation with points & lines:

Manipulate[Graphics[{Rotate[{
Rotate[{Line[{{0, 0}, {(a + b)/2, 0}}], Red, PointSize[Large],
Point[{(a + b)/2, 0}]}, r, {0, 0}],
Rotate[{Line[{{0, 0}, {(a + b)/2, 0}}], Red, PointSize[Large],
Point[{(a + b)/2, 0}]}, -r, {0, 0}],
Rotate[{Line[{{0, 0}, {-a, 0}}], Red, PointSize[Large],
Point[{-a, 0}]}, r, {0, 0}],
Rotate[{Line[{{0, 0}, {-b, 0}}], Red, PointSize[Large],
Point[{-b, 0}]}, -r, {0, 0}]
}, q, {0, 0}]}, Axes -> True, PlotRange -> {{-2, 2}, {-2, 2}}],
{{r, Pi/8}, 0, Pi/2}, {{q, 0}, -Pi/2, Pi/2}, {{a, 1}, 0, 1.5}, {{b, 1}, 0, 1.5}]


Is there any way of getting and using the coordinates of the end-points while they are being manipulated (other than work out their trig relationships ... I anticipate there will be quite a few)?

• rewrite this with RotationTransform.
– Kuba
Oct 7, 2014 at 20:03
• @Kuba will this approach work if I have lots of rotations within rotations? Oct 7, 2014 at 20:14
• @martin: Your rotations are simple rotations about the origin, so a composition of two rotations is just a rotation by the sum of the angles of the individual rotations. Oct 7, 2014 at 20:22
• @DumpsterDoofus the intention is to have lines rotating about the endpoints too ... things could get a little complicated Oct 7, 2014 at 20:28
• @martin Manipulate[ r1 = RotationTransform[q]; r2 = RotationTransform[r]; r3 = RotationTransform[-r]; pkt2 = r1 /@ MapThread[Compose, {{r2, r3, r2, r3}, pkt}]; Grid[{{ Graphics[{ Thick, AbsolutePointSize@7, {Point[#], Line[{{0, 0}, #}]} & /@ pkt2 }, Axes -> True, PlotRange -> {{-2, 2}, {-2, 2}}], Column@pkt2 }}], {{r, Pi/8}, 0, Pi/2}, {{q, 0}, -Pi/2, Pi/2}, {{a, 1}, 0, 1.5}, {{b, 1}, 0, 1.5}, Initialization :> ( pkt := {{(a + b)/2, 0}, {(a + b)/2, 0}, {-a, 0}, {-b, 0}} ), TrackedSymbols :> {a, b, r, q}]
– Kuba
Oct 7, 2014 at 20:39

As Kuba mentioned, you can quite easily work out the trig relations to give the endpoints directly, using RotationTransform:

RotationTransform[q] /@ {RotationTransform[r]@{(a + b)/2, 0},
RotationTransform[-r]@{(a + b)/2, 0}, RotationTransform[r]@{-a, 0},
RotationTransform[-r]@{-b, 0}}


which produces the coordinates of the red dots:

{{1/2 (a + b) Cos[q] Cos[r] - 1/2 (a + b) Sin[q] Sin[r],
1/2 (a + b) Cos[r] Sin[q] +
1/2 (a + b) Cos[q] Sin[r]}, {1/2 (a + b) Cos[q] Cos[r] +
1/2 (a + b) Sin[q] Sin[r],
1/2 (a + b) Cos[r] Sin[q] -
1/2 (a + b) Cos[q] Sin[r]}, {-a Cos[q] Cos[r] +
a Sin[q] Sin[r], -a Cos[r] Sin[q] -
a Cos[q] Sin[r]}, {-b Cos[q] Cos[r] -
b Sin[q] Sin[r], -b Cos[r] Sin[q] + b Cos[q] Sin[r]}}


Similarly, you can add the numerical coordinates to your Manipulate object:

Manipulate[{MatrixForm[
RotationTransform[q] /@ {RotationTransform[r]@{(a + b)/2, 0},
RotationTransform[-r]@{(a + b)/2, 0},
RotationTransform[r]@{-a, 0}, RotationTransform[-r]@{-b, 0}}],
Graphics[{Rotate[{Rotate[{Line[{{0, 0}, {(a + b)/2, 0}}], Red,
PointSize[Large], Point[{(a + b)/2, 0}]}, r, {0, 0}],
Rotate[{Line[{{0, 0}, {(a + b)/2, 0}}], Red, PointSize[Large],
Point[{(a + b)/2, 0}]}, -r, {0, 0}],
Rotate[{Line[{{0, 0}, {-a, 0}}], Red, PointSize[Large],
Point[{-a, 0}]}, r, {0, 0}],
Rotate[{Line[{{0, 0}, {-b, 0}}], Red, PointSize[Large],
Point[{-b, 0}]}, -r, {0, 0}]}, q, {0, 0}]}, Axes -> True,
PlotRange -> {{-2, 2}, {-2, 2}}, ImageSize -> 500]}, {{r, Pi/8}, 0,
Pi/2}, {{q, 0}, -Pi/2, Pi/2}, {{a, 1}, 0, 1.5}, {{b, 1}, 0, 1.5}]


• Thank you so much! I was just about to go about it the old fashioned way with trig .. Oct 7, 2014 at 20:36