Message Boards Message Boards

0
|
7422 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How do I create a function to rotate a rectangle about its origin?

Posted 9 years ago

Hi,

I am new to Mathematica and was trying some new things.

I wanted to rotate a rectangle using a rotation matrix by any angle theta from say o to 2pi.

I could do it using predefined Mathematica functions.

R = Rectangle[{-2.5, -0.5}, {2.5, 0.5}];
Animate[Graphics[GeometricTransformation[R, RotationMatrix[\[Theta]]],
   Axes -> True, PlotRange -> {{-10, 10}, {-10, 10}}], {\[Theta], 0, 
  2 \[Pi]}]

But, say I want to write the 2x2 rotation matrix as a function and do it then how would i proceed?

I defined a 2x2 rotation matrix Rot and tried multiplying every coordinate of the rectangle, but I get an error and the rectangle doesn't rotate

I did the following:

Rot[\[Theta]] = {{Cos[\[Theta]], -Sin[\[Theta]]}, {Sin[\[Theta]], 
    Cos[\[Theta]]}};


R = Rectangle[{-2.5, -0.5}, {2.5, 0.5}];
Animate[Graphics[GeometricTransformation[R, Rot[\[Theta]]], 
  Axes -> True, PlotRange -> {{-10, 10}, {-10, 10}}], {\[Theta], 0, 
  2 \[Pi]}]

Is there a simple way to do this by just defining a function and then using it?Error

Attachments:
POSTED BY: Varun Kulkarni
5 Replies

The rotation matrix by angle a is simply

RotationMatrix[a]

You can use it inside Animate through GeometricTransformation

R0 = Rectangle[{-2.5, -0.5}, {2.5, 0.5}];
Animate[Graphics[GeometricTransformation[R0, RotationMatrix[a]], 
  Axes -> True, PlotRange -> {{-10, 10}, {-10, 10}}], {a, 0, 2 \[Pi]}]

The command Rotate would save you some typing in this kind of situation.

POSTED BY: Gianluca Gorni

It can be shortened to an almost one-liner:

Animate[Graphics[Rotate[Rectangle[{-2.5, -0.5}, {2.5, 0.5}], a], 
  Axes -> True, PlotRange -> 10], {a, 0, 2 \[Pi]}]
POSTED BY: Gianluca Gorni
Posted 9 years ago

I wanted to try and use a 2x2 rotation matrix for the same. Define a 2x2 rotation matrix and then use this defined function inside Animate to rotate the Rectangle

Is there any way to do that?

POSTED BY: Varun Kulkarni

may be

ClearAll[rot,a]
rot[a_] := {{Cos[a], -Sin[a]}, {Sin[a], Cos[a]}};
R0 = Rectangle[{-2.5, -0.5}, {2.5, 0.5}];
Animate[Graphics[GeometricTransformation[R0, rot[a]], Axes -> True, 
  PlotRange -> {{-10, 10}, {-10, 10}}], {a, 0, 2 \[Pi]}]
POSTED BY: Nasser M. Abbasi
Posted 9 years ago

Is there any way that i can rotate this rectangle without using Geometric Transformation?

Say, multiply every end coordinate of the rectangle with the function defined for the rotation matrix?

Multiply every end coordinate with rot [a] where rot[a] := {{Cos[a], -Sin[a]}, {Sin[a], Cos[a]}}; ?

POSTED BY: Varun Kulkarni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract