5
$\begingroup$

I have here an example of how a rotation matrix operates a parametric representation of a square.

R15 = {{Cos[π/12], -Sin[π/12]}, {Sin[π/12], Cos[π/12]}};
R30 = {{Cos[π/6], -Sin[π/6]}, {Sin[π/6], Cos[π/6]}};
R45 = {{Cos[π/4], -Sin[π/4]}, {Sin[π/4], Cos[π/4]}};
R60 = {{Cos[π/3], -Sin[π/3]}, {Sin[π/3], Cos[π/3]}};
R75 = {{Cos[(5 π)/12], -Sin[(5 π)/12]}, {Sin[(5 π)/12], Cos[(5 π)/12]}};

r1 = {t, -1};
r2 = {1, t};
r3 = {t, 1};
r4 = {-1, t};
rsq15 = {R15.r1, R15.r2, R15.r3, R15.r4};
rsq30 = {R30.r1, R30.r2, R30.r3, R30.r4};
rsq45 = {R45.r1, R45.r2, R45.r3, R45.r4};
rsq60 = {R60.r1, R60.r2, R60.r3, R60.r4};
rsq75 = {R75.r1, R75.r2, R75.r3, R75.r4};
ParametricPlot[{sq, rsq15, rsq30, rsq45, rsq60, rsq75}, {t, -1, 1}]

How would you minimize the amount of code necessary?

$\endgroup$
0

5 Answers 5

4
$\begingroup$

If you need a more literal refactoring of your code, rather than bill's Line drawing, consider:

R15 = RotationMatrix[π/12];  (* thanks to J. M. ! *)

rr = {{t, -1}, {1, t}, {t, 1}, {-1, t}};

sqrs = NestList[#.R15 &, rr, 5];

ParametricPlot[sqrs, {t, -1, 1}]

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ R15 = RotationMatrix[π/12]; is shorter. FWIW, here's how to sidestep the use of MatrixPower[] altogether: rr = {{t, -1}, {1, t}, {t, 1}, {-1, t}}; sqrs = Array[rr.RotationMatrix[(1 - #) π/12] &, 5]; ParametricPlot[sqrs, {t, -1, 1}] $\endgroup$ May 26, 2017 at 15:31
  • $\begingroup$ Very nice! Thanks for the lesson. :-) $\endgroup$
    – Mr.Wizard
    May 26, 2017 at 15:32
6
$\begingroup$

You could use graphics objects:

Graphics[Rotate[Line[{{1,1}, {1,-1}, {-1,-1}, {-1,1}, {1,1}}], #]
    &/@ Range[Pi/16, Pi/2, Pi/16]]

enter image description here

$\endgroup$
0
6
$\begingroup$

Personally, I would recommend that such figures be generated from primitives, as in bill's answer. Nevertheless, allow me to present a slight curiosity based on this math.SE answer:

PolarPlot[Table[Sec[Mod[θ - k π/12, π/2] - π/4], {k, -3, 2}] // Evaluate, {θ, 0, 2 π}]

squares

$\endgroup$
3
$\begingroup$
rr = {{t, -1}, {1, t}, {t, 1}, {-1, t}};
rotations = Map[RotationTransform[#][rr] &, Range[0, 2 Pi, 2 Pi/5]];
ParametricPlot[rotations, {t, -1, 1}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ You can also use Graphics@Table[Line@CirclePoints[{1,θ},4], {θ, 0, π, π/8}] $\endgroup$ May 26, 2017 at 19:24
2
$\begingroup$

You've got several choices for the basic square:

Line[{{1, 1}, {1, -1}, {-1, -1}, {-1, 1}, {1, 1}}]

or, with FaceForm[], EdgeForm[Black], either of

Polygon@CirclePoints[Sqrt[2], 4]
Rectangle[{-1, -1}, {1, 1}]

Then I'd probably use GeometricTransform:

Graphics[{
  FaceForm[], EdgeForm[Black],
  GeometricTransformation[
   Rectangle[{-1, -1}, {1, 1}],
   RotationMatrix /@ (Pi Range[8]/16)
   ]
  }]

But this explicitly constructs all the coordinates:

Graphics[{
  FaceForm[], EdgeForm[Black],
  Polygon@ Transpose[
    CirclePoints[Sqrt[2], 4] . Transpose[RotationMatrix /@ (Pi Range[8]/16), {2, 3, 1}]] 
   ]
  }]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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