Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to rotate a series of lines by the same angle around their centre point. Say each line is defined by a co-ordinate at each end, simplified example below of a typical dataset.

foo = {{{100, 25}, {150, 45}}, {{200, 45}, {240, 85}}};

Then the midpoint can be found by:-

boo = (#[[2]] - #[[1]])/2 + #[[1]] & /@ foo;

This is visualised using the code below:

Show[
Graphics[{Thick, Dashed, Black, Line /@ foo}],
Graphics[{Black, PointSize[Large],
Point[boo],
Table[{Black, Text[ToString[boo[[p]]], boo[[p]] + 2]}, {p, Length[boo]}]}]
]

enter image description here

I was hoping to create a series of transformations using RotationTransform such as below:

rot = RotationTransform[Pi/2, #] & /@ boo

Then mapping this across foo using MapThread, but I'm not sure which function I should be mapping across to make each line rotate by 90 degrees around its own centre point.

MapThread[?, {woo, rot}]

I think I'm close to what I want to achieve (or maybe not), but I can't quite seem to close it out. All suggestions welcome.

share|improve this question

3 Answers 3

up vote 4 down vote accepted
grF := Function[{angle},
             Graphics[{Thick, Dashed, Black, Line@#,
             Red, GeometricTransformation[Line@#, 
                                     RotationTransform[angle, Mean@#]],
             Black, PointSize[Large], Point[Mean@#],
             Text[ToString[Mean@#], Mean@# + 2]} & /@ #] &]

grF[Pi/2]@foo

enter image description here

ListAnimate[Table[Show[grF[i]@foo, PlotRange -> {{50, 250}, {0, 100}}],
                 {i, -Pi,  Pi, Pi/32}]]

enter image description here

share|improve this answer

1:

lines = {{{100, 25}, {150, 45}}, {{200, 45}, {240, 85}}};
f[{p1_, p2_}, theta_] := Module[{mid},
   mid = (p2 - p1)/2 + p1;
   RotationTransform[theta, mid][#] & /@ {p1, p2}
  ];
lines2 = f[#, Pi/6] & /@ lines;
Graphics[{Red, Line[lines], Blue, Line[lines2]}]

enter image description here

2:

lines = {{{100, 25}, {150, 45}}, {{200, 45}, {240, 85}}};
lines2 = RotationTransform[Pi/6, (#2 - #1)/2 + #1][{#1, #2}] & @@@ lines;
Graphics[{Red, Line[lines], Blue, Line[lines2]}]
share|improve this answer
foo = {{{100, 25}, {150, 45}}, {{200, 45}, {240, 85}}};
Manipulate[
 Graphics[{Line@#, Blue, Rotate[Line@#, t, Mean@#], Transparent, 
          Circle[Mean@#,EuclideanDistance @@ #/2]} & /@ foo], {t,0, 2 Pi}]

The transparent circles are there to pre-calculate the maximum Plot Range.

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.