Advertisement
Matthen

Rolling shapes

Jun 19th, 2011
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. (*define r of theta here:*)
  2. superellipse[\[Theta]_, m_,
  3. n_] := (Cos[m \[Theta] /4]^(2 n) + Sin[m \[Theta] /4]^(
  4. 2 n))^(-1/(2 n));
  5. r[\[Theta]_] := 1/(1 + 0.9 Cos[\[Theta]]);
  6. r[\[Theta]_] := superellipse[\[Theta], 4, 10];
  7. y[\[Theta]_] := r[\[Theta]] Sin[\[Theta]];
  8. x[\[Theta]_] := r[\[Theta]] Cos[\[Theta]];
  9. angle[\[Theta]_] := ArcTan[x'[\[Theta]], y'[\[Theta]]];
  10. soln = NDSolve[{xt'[t] == Sqrt[r'[t]^2 + r[t]^2], xt[0] == 0},
  11. xt[t], {t, 0, 4 Pi}];
  12. X[tt_] := First[xt[t] /. soln /. {t -> tt}];
  13. point[t_, tt_] := {X[t], 0} +
  14. RotationMatrix[-angle[t]].(r[tt] {Cos[tt], Sin[tt]} -
  15. r[t] {Cos[t], Sin[t]});
  16. Manipulate[
  17. Show[Graphics[{PointSize[Medium], Point[point[\[Tau], \[Alpha]]]},
  18. PlotRange -> {{X[0] - 3, X[4 Pi] + 3}, {-1, 3}},
  19. ImageSize -> {500}],
  20. ParametricPlot[point[\[Tau], tt], {tt, 0, 2 Pi},
  21. PlotStyle -> Darker@Red],
  22. ParametricPlot[point[tt, \[Alpha]], {tt, 0, \[Tau]},
  23. PlotStyle -> Red]], {\[Tau], 10^-3, 4 Pi}, {\[Alpha], 0, 2 Pi}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement