
Re: how does Rotate in 2D work?
Posted:
Aug 14, 2012 5:04 AM


The answer to the question "How can I use the Rotate command so that the _origin_ of the arrow or the Line I want to rotate is where the rotation occur around?" is given by the following replacement function:
altRotate[g_, \[Theta]_, {x_, y_}] := Rotate[g, \[Theta], ({x, y}  RotationTransform[\[Theta]][{x, y}])/( 2  2 Cos[\[Theta]])] /; Mod[\[Theta], \[Pi]] != 0
Here it is using the example given:
Graphics[{altRotate[Arrow[{{0, 0}, {1, 0}}], 90 Degree, {1, 0}]}, Axes > True]
To understand why this is the correct answer, note that Rotate[g_, \[Theta]_, {x_, y_}] gives the same transformation as GeometricTransformation[g, RotationTransform[\[Theta], {x, y}]] as shown by the following two examples:
Manipulate[ Graphics[{{Dashed, Circle[pt, Norm[pt]]}, Table[Rotate[{Hue[\[Theta]/2/\[Pi]], Arrow[{{0, 0}, {1, 0}}], Line[{{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}}]}, \[Theta] , pt], {\[Theta], 0, 2 \[Pi], \[Pi]/3}]}, Axes > True, PlotRange > {{8, 8}, {8, 8}}], {{pt, {2, 2}}, Locator}]
Manipulate[ Graphics[{{Dashed, Circle[pt, Norm[pt]]}, Table[GeometricTransformation[{Hue[\[Theta]/2/\[Pi]], Arrow[{{0, 0}, {1, 0}}], Line[{{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}}]}, RotationTransform[\[Theta], pt]], {\[Theta], 0, 2 \[Pi], \[Pi]/3}]}, Axes > True, PlotRange > {{8, 8}, {8, 8}}], {{pt, {2, 2}}, Locator}]
Then further note that:
RotationTransform[\[Theta], {x, y}] == Composition[TranslationTransform[{x, y}], RotationTransform[\[Theta] ], TranslationTransform[{x, y}]] == Composition[TranslationTransform[{x, y}], TranslationTransform[RotationTransform[\[Theta] ][{x, y}]], RotationTransform[\[Theta] ]] == Composition[TranslationTransform[{x, y}  RotationTransform[\[Theta] ][{x, y}]], RotationTransform[\[Theta] ]]
Since the desired transformation is equivalent to Composition[TranslationTransform[{u, v}], RotationTransform[\[Theta] ] ] then it is clear that we must solve for {x, y} in terms of {u, v}:
In[174]:= Simplify[{x, y} /. Solve[{x, y}  RotationTransform[\[Theta] ][{x, y}] == {u, v}, {x, y}]][[1]] Out[174]= {1/2 (u  v Cot[\[Theta]/2]), 1/2 (v + u Cot[\[Theta]/2])}
Which is the same result as given by:
In[176]:= FullSimplify[({u, v}  RotationTransform[\[Theta]][{u, v}])/ (2  2 Cos[\[Theta]])] Out[176]= {1/2 (u  v Cot[\[Theta]/2]), 1/2 (v + u Cot[\[Theta]/2])}
Note also that:
Composition[TranslationTransform[{x, y}], RotationTransform[\[Theta]]] == AffineTransform[{RotationMatrix[\[Theta] ], {x, y}}]
So we could also create another very simple function to replace Rotate:
tRotate[g_, \[Theta]_, {x_, y_}] := GeometricTransformation[g, AffineTransform[{RotationMatrix[\[Theta] ], {x, y}}]]
And use it like so:
Graphics[{tRotate[Arrow[{{0, 0}, {1, 0}}], 90 Degree, {1, 0}]}, Axes > True]
Hope this helps...
"Nasser M. Abbasi" <nma@12000.org> wrote in message news:jvt3om$luo$1@smc.vnet.net... > > Suppose I have an arrow Arrow[{{0,0},{0,1}}] and I want > to rotate it 90 degrees, but taking the origin of the arrow > to be the point {0.5,0} when doing the rotation, instead of > the point {0,0} as it is above. > > i.e. given > >  >  > +> > (0,0) (1,0) > > Now if I do Rotate on the above, by 90 degrees, with {0,0} as > origin, it gives, using the command > > Graphics[{ > Rotate[Arrow[{{0, 0}, {1, 0}}], 90 Degree, {0, 0}] > }, Axes > True] > > > (0,1) ^ >  >  > + > (0,0) > > > So far so good. Now, I want to obtain this > > ^ >  >   > ++ > (0,0) (1,0) > > i.e. I want the rotation to be around (1,0), and not (0,0). > I thought I can do it using the same command above, by just > changing {0,0} to {1,0} like this > > Graphics[{ > Rotate[Arrow[{{0, 0}, {1, 0}}], 90 Degree, {1, 0}] > }, Axes > True] > > But the above gave > >  (1,0) > ++ > (0,0) ^ >  >  > > It is more strange when asking for rotation around say (.5,0), > > Graphics[{ > Rotate[Arrow[{{0, 0}, {1, 0}}], 90 Degree, {.5, 0}] > }, Axes > True] > > Now it gives > ^ >   > + > (0,0) (0.5,0) >  >  > > So, I think this has to do what that 'bounding box' that help talks about, > but ofcourse help does not say how to change this or anything, and no > examples. > > question is: > How can I use the Rotate command so that the _origin_ of the arrow > or the Line I want to rotate is where the rotation occur around? i.e > I want the arrow to be based from that rotation point before the > rotation start. > > (I know there other ways to do this, using RotationMatrix and such, > but I wanted to find how to do it using Rotate). I think the > problem is with the Bounding Box thing, which I do not > understand now how to change in this case. > > ps. Please WRI, improve your help pages more. Add more 'words' and > do not be so brief and cryptic in the description and add more > examples and add links to things you mention. > > thanks. > Nasser > > > > > >

