Matthen

Rolling a square

Jun 18th, 2011
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. corner[x_] :=
  2. Module[{\[Theta] = N@SawtoothWave[{0, 2 Pi}, x/(2 Pi)]}, Piecewise[{
  3. {{-1 - Cos[\[Theta]], Sin[\[Theta]]}, 0 <= \[Theta] < Pi/2},
  4. {{-Sqrt[2] Cos[\[Theta] - Pi/4], Sqrt[2] Sin[\[Theta] - Pi/4]},
  5. Pi/2 <= \[Theta] < Pi},
  6. {{1 + Sin[\[Theta] - Pi], Cos[\[Theta] - Pi]},
  7. Pi <= \[Theta] < 3 Pi/2},
  8. {{2, 0}, \[Theta] >= 3 Pi/2}
  9. }] + {4 Floor[x/(2 Pi)], 0}
  10. ];
  11.  
  12. frame[\[Theta]_] := Module[{t},
  13. t = If[\[Theta] <= 3.5 Pi, \[Theta], 7 Pi - \[Theta]];
  14. Show[Graphics[{
  15. RGBColor[0.8, 0.3, 0.2],
  16. Polygon[{corner[t], corner[t + Pi/2] - {1, 0},
  17. corner[t + Pi] - {2, 0}, corner[t + 3 Pi/2] - {3, 0}}
  18. ], Black,
  19. PointSize[Medium], Point[corner[t]]
  20. }
  21. , PlotRange -> {{-2, 5}, {-0.1, 1.5}}],
  22. If[\[Theta] >= 3.5 Pi,
  23. ParametricPlot[corner[x], {x, t, 3.5 Pi + 0.001},
  24. PlotStyle -> Black]
  25. ,
  26. Graphics[]]
  27. ]];
  28.  
  29. Manipulate[frame[\[Theta]], {\[Theta], 0, 7 Pi}]
Advertisement
Add Comment
Please, Sign In to add comment