Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11265 > unrolled thread

how does Rotate in 2D work?

Started by"Nasser M. Abbasi" <nma@12000.org>
First post2012-08-08 07:16 +0000
Last post2012-08-14 09:04 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  how does Rotate in 2D work? "Nasser M. Abbasi" <nma@12000.org> - 2012-08-08 07:16 +0000
    Re: how does Rotate in 2D work? "Alexander Elkins" <alexander_elkins@hotmail.com> - 2012-08-14 09:04 +0000

#11265 — how does Rotate in 2D work?

From"Nasser M. Abbasi" <nma@12000.org>
Date2012-08-08 07:16 +0000
Subjecthow does Rotate in 2D work?
Message-ID<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





[toc] | [next] | [standalone]


#11335

From"Alexander Elkins" <alexander_elkins@hotmail.com>
Date2012-08-14 09:04 +0000
Message-ID<k0d4a9$m87$1@smc.vnet.net>
In reply to#11265
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
>
>
>
>
>
>



[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web