# How do I create a function to rotate a rectangle about its origin? [closed]

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?

## closed as off-topic by MarcoB, Sjoerd C. de Vries, user9660, dr.blochwave, Oleksandr R.Nov 11 '15 at 9:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Sjoerd C. de Vries, Community, dr.blochwave, Oleksandr R.
If this question can be reworded to fit the rules in the help center, please edit the question.

• 1. Don't use MatrixForm[] here, as it is only intended for output formatting. 2. RotationMatrix[] is built-in. – J. M. will be back soon Nov 11 '15 at 4:41
• I don't want to use the inbuilt Mathematica function RotationMatrix[]. But instead define a function for the 2x2 rotation matrix and then use it to rotate the rectangle as shown in the image. Thanks – Varun Kulkarni Nov 11 '15 at 4:47
• Then, you can just do With[{θ = π/6}, Graphics[GeometricTransformation[Rectangle[{-2.5, -0.5}, {2.5, 0.5}], {{Cos[θ], -Sin[θ]}, {Sin[θ], Cos[θ]}}]]]. But, it seems you have a more fundamental problem. Execute Remove[Rot], and try using Rot[θ_] := {{Cos[θ], -Sin[θ]}, {Sin[θ], Cos[θ]}}. (Note the difference!) – J. M. will be back soon Nov 11 '15 at 4:51
• Thanks, but if I wanted to do something like this: Rot[[Theta]_] := {{Cos[[Theta]], -Sin[[Theta]]}, {Sin[[Theta]], Cos[[Theta]]}}; R = Rectangle[{-2.5, -0.5}, {2.5, 0.5}]; Animate[Show[Graphics[R, Rot[[Theta]]], Axes -> True, PlotRange -> {{-10, 10}, {-10, 10}}], {[Theta], 0, 2 [Pi]}] , Where initially I have defined a function then how do I proceed? It is similar to the image posted initially – Varun Kulkarni Nov 11 '15 at 4:56
• It should work. From your screenshot, it seems you used Rot for something different, but forgot to clear it. – J. M. will be back soon Nov 11 '15 at 5:05

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


As per your comment, if you do not want to use the built in RotationMatrix then please see this:

...and this:

• Thanks. But instead of using RotationMatrix[[Theta]], I want to define a 2x2 Rotation Matrix say Rot[[Theta]_] := {{Cos[[Theta]], -Sin[[Theta]]}, {Sin[[Theta]], Cos[[Theta]]}}; and then use this function to rotate the rectangle. Also, it would be helpful if I could use Show[] in Animate alongwith PlotRange Thanks – Varun Kulkarni Nov 11 '15 at 4:52
• @VarunKulkarni explain why you want to use Show – Mike Honeychurch Nov 11 '15 at 4:55
• 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]}] This is how I have done , but now I want to define a function for that, and that function is a 2x2 Rotation matrix ....Heres what I am trying Rot[[Theta]_] := {{Cos[[Theta]], -Sin[[Theta]]}, {Sin[[Theta]], Cos[[Theta]]}}; R = Rectangle[{-2.5, -0.5}, {2.5, 0.5}]; Animate[Show[Graphics[R, Rot[[Theta]]], Axes -> True, PlotRange -> {{-10, 10}, {-10, 10}}], {[Theta], 0, 2 [Pi]}] – Varun Kulkarni Nov 11 '15 at 4:59
• @VarunKulkarni before doing any of this you need to learn basic Mathematica syntax. {[Theta], 0, 2 [Pi]} is invalid, Sin[[Theta]] is invalid etc, Show is redundant, and so on – Mike Honeychurch Nov 11 '15 at 5:04
• @MikeHoneychurch the user probably did not type this as it appears; the StackExchange software eats \ if one isn't careful. I think the syntax was most likely valid. – Oleksandr R. Nov 11 '15 at 9:28