# [GIF] Rolling (Circles rolling inside a circle)

Posted 7 months ago
1306 Views
|
2 Replies
|
5 Total Likes
|
 This one is pretty simple: take two circles of radius 1/2 rolling inside a unit circle and track a point on each circle's perimeter. The points turn out to follow straight lines, and the challenge is to make this seem both surprising and obvious (and also to fit it all under 3 MB). Not sure if I succeeded, but that was the idea, anyway.Here's the code: smoothstep[x_] := 3 x^2 - 2 x^3; With[{a = 1, b = 1/2, cols = RGBColor /@ {"#303841", "#f3f6f6"}}, Manipulate[ Graphics[{ Thickness[.0075], cols[[1]], Opacity[ Which[t < 8 π, 1, 8 π <= t < 12 π, 1 - smoothstep[(t - 8 π)/(4 π)], 12 π <= t < 14 π, 0, 14 π <= t <= 18 π, smoothstep[(t - 14 π)/(4 π)]]], Table[ Circle[(a - b) {Cos[t + π i], Sin[t + π i]}, b], {i, 0, 1}], Opacity[ Which[t < 6 π, 0, 6 π <= t < 8 π, smoothstep[(t - 6 π)/(2 π)], 8 π <= t < 14 π, 1, 14 π <= t <= 18 π, 1 - smoothstep[(t - 14 π)/(4 π)]]], Thickness[.01], Line[ Table[(a - b) {Cos[s], Sin[s]} + b {Cos[-(a - b)/b s], Sin[-(a - b)/b s]}, {s, t - 3 π/4, t, π/100}], VertexColors -> Table[Blend[{Directive[cols[[2]], Opacity[0]], cols[[1]]}, s], {s, 0, 1, 1/75}]], Line[ Table[(a - b) {Cos[s + π], Sin[s + π]} + b {Cos[-(a - b)/b s], Sin[-(a - b)/b s]}, {s, t - 3 π/4, t, π/100}], VertexColors -> Table[Blend[{Directive[cols[[2]], Opacity[0]], cols[[1]]}, s], {s, 0, 1, 1/75}]], Opacity[1], cols[[1]], Thickness[.0075], Circle[], PointSize[.03], Table[ Point[(a - b) {Cos[t + i π], Sin[t + i π]} + b {Cos[-(a - b)/b t], Sin[-(a - b)/b t]}], {i, 0, 1}]}, Background -> cols[[-1]], PlotRange -> Sqrt[2], ImageSize -> 540], {t, 0, 18 π}] ] 
2 Replies
Sort By:
Posted 7 months ago
 - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming, and consider contributing your work to the The Notebook Archive!
 This is a very lovely demonstration of La Hire's line (or the "two-cusp hypocycloid"). A related demonstration can be found in this Mathematica Stack Exchange post.Having gotten the "name dropping for search engines" out of the way, here's my version of Clayton's code: With[{a = 1, b = 1/2, cols = RGBColor /@ {"#303841", "#f3f6f6"}}, DynamicModule[{clist = Map[RGBColor, Transpose[{1 - #, #} & @ Subdivide[75]]. {Append[List @@ cols[[2]], 0], Append[List @@ cols[[1]], 1]}], iF1 = Interpolation[{{{0}, 1, 0}, {{8 π}, 1, 0}, {{12 π}, 0, 0}, {{14 π}, 0, 0}, {{18 π}, 1, 0}}], iF2 = Interpolation[{{{0}, 0, 0}, {{6 π}, 0, 0}, {{8 π}, 1, 0}, {{14 π}, 1, 0}, {{18 π}, 0, 0}}]}, Manipulate[Graphics[{{Directive[Thickness[.0075], Append[cols[[1]], iF1[t]]], Table[Circle[ReIm[(a - b) Exp[I (t + π i)]], b], {i, 0, 1}]}, {Directive[Opacity[iF2[t]], Thickness[.01]], Line[ReIm[Table[(a - b) Exp[I s] + b Exp[-I (a - b)/b s], {s, t - 3 π/4, t, π/100}]], VertexColors -> clist], Line[ReIm[Table[(a - b) Exp[I (s + π)] + b Exp[-I (a - b)/b s], {s, t - 3 π/4, t, π/100}]], VertexColors -> clist]}, {Directive[cols[[1]], Thickness[.0075]], Circle[]}, {Directive[cols[[1]], PointSize[.03]], Point[ReIm[Table[(a - b) Exp[I (t + i π)] + b Exp[-I (a - b)/b t], {i, 0, 1}]]]}}, Background -> cols[[-1]], PlotRange -> Sqrt[2], ImageSize -> 540], {t, 0, 18 π}]]] Notes on the code, in no particular order: I often prefer the complex formulation whenever I deal with epi- or hypocycloids; that way, I don't have to worry about whether I used the same argument in the sine and cosine for the components. Since smoothstep was only being used here for keyframing purposes, it is more compact and equivalent to directly construct a piecewise Hermite interpolant instead, which Interpolation[] has no trouble doing. (If you need further convincing, compare the InterpolatingFunction[] in my version and the Which[]-based function in Clayton's version in a plot.) The snippet Append[List @@ color, 0] effectively adds an alpha channel to color. Since the list of colors used in VertexColors does not change, one can just generate the list once and then plug it into the Manipulate[] with DynamicModule[]. (Note also the slightly different method to get a pile of linearly interpolated colors all at once.)