Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inverse[s_, s3_, x_] := Module[{s4},
- s4 = Map[Join[#, {1}] &, s3];
- Map[#[x[[1]], x[[2]], 1] &, ({LinearModelFit[{s4, First /@ s}],
- LinearModelFit[{s4, Last /@ s}]})]
- ];
- Dudeney[t_, T_] :=
- Module[{a, b, c, n, m, x, l, k, h, p, q, r, s, angle, q1, r1, s1, m1,
- l1, m2, q2, r2, s2, l2, l3, m3, p3, q3, r3, s3, p1, p2,
- M},(*The vertices of an equilateral triangle are:*){a, b, c} =
- Map[RotationMatrix[# 2 N[Pi]/3].{0, 1} &, {0, 1, 2}];
- (*The midpoints of ab and ac are*)n = (a + b)/2;
- m = (a + c)/2;
- (*The quarter and three-quarter points of bc are*)
- x = b + (c - b)/4;
- l = b + 3 (c - b)/4;
- (*From n,draw a perpendicular to meet mx at k,
- and from l draw another one to meet mx at h.*)
- k = Projection[n - x, m - x] + x;
- h = Projection[l - x, m - x] + x;
- (*At time zero,
- the original triangle abc is cut up into three quadrilaterals,p,q,
- and r and and a small triangle,s.*)p = {b, n, k, x};
- q = {a, n, k, m};
- r = {c, m, h, l};
- s = {x, l, h};
- (*The pieces q,
- r and s are rotated about moving hinges which were originally at n,
- m,and l.*)
- If[T <= 0.25,
- angle = N[Pi] (t - 1)/(T - 1);
- ,
- angle = N[Pi] (t - 1)/((0.5 - T) - 1);
- ];
- q1 = Map[n + RotationMatrix[angle].(# - n) &, q];
- r1 = Map[n + RotationMatrix[angle].(# - n) &, r];
- s1 = Map[n + RotationMatrix[angle].(# - n) &, s];
- {m1, l1} = Map[n + RotationMatrix[angle].(# - n) &, {m, l}];
- r2 = Map[m1 + RotationMatrix[angle].(# - m1) &, r1];
- s2 = Map[m1 + RotationMatrix[angle].(# - m1) &, s1];
- l2 = m1 + RotationMatrix[angle].(l1 - m1);
- s3 = Map[l2 + RotationMatrix[angle].(# - l2) &, s2];
- If[T > 0.25,
- p = Map[inverse[s, s3, #] &, p];
- q1 = Map[inverse[s, s3, #] &, q1];
- r2 = Map[inverse[s, s3, #] &, r2];
- s3 = Map[inverse[s, s3, #] &, s3];
- ];
- Graphics[{EdgeForm[Black], RGBColor[0.7, 0.2, 0.6], Polygon@p,
- RGBColor[0.7, 0.6, 0.8], Polygon@q1, RGBColor[.9, .71, .26],
- Polygon@r2, RGBColor[0, 0.7, 0.5], Polygon@s3
- }, PlotRange -> {{-3, 3}, {-3, 3}}, AspectRatio -> Automatic,
- Axes -> None, ImageSize -> {450, 450}]];
- f[t_] := (Tanh[20 (t - 0.125)] + 1)/8 + (Tanh[20 (t - 0.325)] + 1)/8;
- Plot[f[t], {t, 0, 0.5}, PlotRange -> {-0.1, 0.5}];
- Manipulate[Dudeney[4, f[t]], {t, 0, 0.5}, SaveDefinitions -> True]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement