(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 7.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 19282, 496] NotebookOptionsPosition[ 18658, 469] NotebookOutlinePosition[ 19001, 484] CellTagsIndexPosition[ 18958, 481] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Stick Puzzles", "Title", CellChangeTimes->{{3.4995621773389997`*^9, 3.4995621996070004`*^9}, { 3.505396434719*^9, 3.505396441935*^9}, 3.505396642558*^9}], Cell["\<\ Generates a range of interlocking puzzles. G. Hart. Jan 2011 (Bridges 2011 paper.)\ \>", "Text", CellChangeTimes->{{3.505396649888*^9, 3.505396717459*^9}, {3.505396973646*^9, 3.505397006119*^9}, {3.5062486028111334`*^9, 3.506248603731535*^9}}], Cell[CellGroupData[{ Cell["Prism to connect two endpoints", "Subsection", CellChangeTimes->{{3.501280308495*^9, 3.501280321415*^9}, {3.505398027618*^9, 3.505398037491*^9}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"mag", "[", "v_", "]"}], ":=", RowBox[{"Sqrt", "[", RowBox[{"v", ".", "v"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"unit", "[", "v_", "]"}], ":=", RowBox[{"v", "/", RowBox[{"mag", "[", "v", "]"}]}]}], ";"}], "\n", RowBox[{ RowBox[{ RowBox[{ RowBox[{"vP", "[", RowBox[{"i_", ",", "n_", ",", " ", "r_", ",", " ", "z_", ",", "alpha_"}], "]"}], ":=", RowBox[{ RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"p", "=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"1", "/", "n"}], "-", RowBox[{"1", "/", "2"}]}], ")"}], "Pi"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"r", " ", RowBox[{"Cos", "[", RowBox[{ RowBox[{"2", " ", "Pi", " ", RowBox[{"i", "/", "n"}]}], "+", "p"}], "]"}]}], ",", RowBox[{"alpha", " ", "r", " ", RowBox[{"Sin", "[", RowBox[{ RowBox[{"2", " ", "Pi", " ", RowBox[{"i", "/", "n"}]}], "+", "p"}], "]"}]}], ",", "z"}], "}"}]}], "]"}], "//", "N"}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"vertex", " ", "i", " ", "of", " ", "n"}], "-", RowBox[{"gon", " ", "parallel", " ", "to", " ", "XY", " ", RowBox[{"plane", ".", " ", "Phase"}], " ", "p", " ", "chosen", " ", "so", " ", "a", " ", "flat", " ", "is", " ", "parallel", " ", "to", " ", "x", " ", "axis"}]}], " ", "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"prism", "[", RowBox[{"n_", ",", "r_", ",", "h_", ",", "alpha_"}], "]"}], ":=", RowBox[{"{", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"prism", " ", "on", " ", "polygon"}], ",", " ", RowBox[{ RowBox[{"from", " ", "z"}], "=", RowBox[{ RowBox[{"+", RowBox[{"/", RowBox[{"-", RowBox[{"h", ".", " ", "2"}]}]}]}], " ", "bases", " ", "and", " ", "n", " ", "sides"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Polygon", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"vP", "[", RowBox[{"i", ",", "n", ",", "r", ",", RowBox[{"-", "h"}], ",", "alpha"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "n", ",", "1", ",", RowBox[{"-", "1"}]}], "}"}]}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Polygon", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"vP", "[", RowBox[{"i", ",", "n", ",", "r", ",", "h", ",", "alpha"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Table", "[", RowBox[{ RowBox[{"Polygon", "[", RowBox[{"{", RowBox[{ RowBox[{"vP", "[", RowBox[{"i", ",", "n", ",", "r", ",", RowBox[{"-", "h"}], ",", "alpha"}], "]"}], ",", RowBox[{"vP", "[", RowBox[{ RowBox[{"i", "+", "1"}], ",", "n", ",", "r", ",", RowBox[{"-", "h"}], ",", "alpha"}], "]"}], ",", RowBox[{"vP", "[", RowBox[{ RowBox[{"i", "+", "1"}], ",", "n", ",", "r", ",", "h", ",", "alpha"}], "]"}], ",", RowBox[{"vP", "[", RowBox[{"i", ",", "n", ",", "r", ",", "h", ",", "alpha"}], "]"}]}], "}"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"stick", "[", RowBox[{ RowBox[{"{", RowBox[{"v0_", ",", "v1_"}], "}"}], ",", "r_", ",", "n_", ",", "alpha_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"newX", ",", "newY", ",", "newZ", ",", "transform"}], "}"}], ",", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"newY", "=", RowBox[{"unit", "[", RowBox[{"v0", "+", "v1"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"newZ", "=", RowBox[{"unit", "[", RowBox[{"v1", "-", "v0"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"newX", "=", RowBox[{"Cross", "[", RowBox[{"newY", ",", "newZ"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"transform", "=", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"newX", ",", "newY", ",", "newZ"}], "}"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"GeometricTransformation", "[", RowBox[{ RowBox[{"prism", "[", RowBox[{"n", ",", "r", ",", RowBox[{"mag", "[", RowBox[{"v1", "-", "v0"}], "]"}], ",", "alpha"}], "]"}], ",", RowBox[{"{", RowBox[{"transform", ",", RowBox[{ RowBox[{"(", RowBox[{"v0", "+", "v1"}], ")"}], "/", "2"}]}], "}"}]}], "]"}]}], ")"}]}], "]"}]}], "\n", RowBox[{ RowBox[{"polyChoices", "=", RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\"", ",", "\"\\"", ",", "\"\\""}], "}"}]}], ";"}], "\[IndentingNewLine]", RowBox[{" ", RowBox[{ RowBox[{ RowBox[{"sticks", "[", RowBox[{ "nSides_", ",", "rad_", ",", "len_", ",", "rot_", ",", "alpha_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Rotate", "[", RowBox[{ RowBox[{"stick", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"mid", "[", "i", "]"}], "+", RowBox[{"len", " ", RowBox[{"dir", "[", "i", "]"}]}]}], ",", RowBox[{ RowBox[{"mid", "[", "i", "]"}], "-", RowBox[{"len", " ", RowBox[{"dir", "[", "i", "]"}]}]}]}], "}"}], ",", "rad", ",", "nSides", ",", "alpha"}], " ", "]"}], ",", RowBox[{"rot", " ", "Degree"}], ",", RowBox[{"mid", "[", "i", "]"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", RowBox[{"Length", "[", "e", "]"}]}], "}"}]}], "]"}]}], ";"}]}], "\n", RowBox[{ RowBox[{ RowBox[{ RowBox[{"end", "[", RowBox[{"i_", ",", "j_"}], "]"}], ":=", RowBox[{"2", RowBox[{"v", "[", RowBox[{"[", RowBox[{"e", "[", RowBox[{"[", RowBox[{"i", ",", "j"}], "]"}], "]"}], "]"}], "]"}]}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"edge", " ", RowBox[{"i", ".", " ", "j"}], " ", "is", " ", "1", " ", "or", " ", "2", " ", "for", " ", "two", " ", "ends"}], " ", "*)"}]}], "\n", RowBox[{ RowBox[{ RowBox[{ RowBox[{"mid", "[", "i_", "]"}], ":=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"end", "[", RowBox[{"i", ",", "1"}], "]"}], "+", RowBox[{"end", "[", RowBox[{"i", ",", "2"}], "]"}]}], ")"}], "/", "2"}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{"midpoint", " ", "of", " ", "edge", " ", "i"}], " ", "*)"}]}], "\n", RowBox[{ RowBox[{ RowBox[{ RowBox[{"dir", "[", "i_", "]"}], ":=", RowBox[{ RowBox[{"end", "[", RowBox[{"i", ",", "1"}], "]"}], "-", RowBox[{"mid", "[", "i", "]"}]}]}], ";"}], " ", RowBox[{"(*", " ", RowBox[{ "direction", " ", "from", " ", "midpoint", " ", "to", " ", "one", " ", "end"}], " ", "*)"}], "\n"}], "\[IndentingNewLine]", RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"v", "=", RowBox[{ RowBox[{ RowBox[{"PolyhedronData", "[", RowBox[{"p", ",", "\"\\""}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}], "//", "N"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{"XYZ", " ", "coords", " ", "of", " ", "vertices"}], " ", "*)"}], "\n", " ", RowBox[{"e", "=", RowBox[{ RowBox[{ RowBox[{"PolyhedronData", "[", RowBox[{"p", ",", "\"\\""}], "]"}], "[", RowBox[{"[", "2", "]"}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], ";", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"list", " ", "of", " ", "edges"}], ",", " ", RowBox[{ "as", " ", "pairs", " ", "of", " ", "indices", " ", "into", " ", "v"}]}], " ", "*)"}], "\n", " ", RowBox[{"g", "=", RowBox[{"Graphics3D", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"sticks", "[", RowBox[{ "nSides", ",", "rad", ",", "len", ",", "rot", ",", "alpha"}], "]"}], ",", RowBox[{"If", "[", RowBox[{"mirror", ",", RowBox[{"sticks", "[", RowBox[{"nSides", ",", RowBox[{"rad", "/", "2"}], ",", "len", ",", RowBox[{"-", "rot"}], ",", "alpha"}], "]"}], ",", RowBox[{"{", "}"}]}], "]"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"Boxed", "\[Rule]", "False"}], ",", RowBox[{"SphericalRegion", "\[Rule]", "True"}]}], "]"}]}]}], "\[IndentingNewLine]", ")"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"rad", ",", ".2"}], "}"}], ",", "0.001", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"len", ",", "1"}], "}"}], ",", "0.001", ",", "5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"rot", ",", "0"}], "}"}], ",", RowBox[{"-", "180"}], ",", "180", ",", RowBox[{"Appearance", "\[Rule]", "\"\\""}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"nSides", ",", "4"}], "}"}], ",", "3", ",", "24", ",", "1", ",", RowBox[{"Appearance", "\[Rule]", "\"\\""}]}], "}"}], ",", RowBox[{"{", RowBox[{"p", ",", "polyChoices"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"alpha", ",", "1"}], "}"}], ",", "0.1", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"mirror", ",", RowBox[{"{", RowBox[{"False", ",", "True"}], "}"}]}], "}"}]}], "]"}], "\[IndentingNewLine]"}], "Input", CellChangeTimes->{{3.501277753033*^9, 3.501277854023*^9}, {3.501277890689*^9, 3.501278022541*^9}, {3.5012781642349997`*^9, 3.501278194157*^9}, { 3.501278226508*^9, 3.501278231446*^9}, {3.501278265118*^9, 3.501278575987*^9}, {3.501278622505*^9, 3.501278714617*^9}, { 3.501278745683*^9, 3.5012788386359997`*^9}, 3.501279087443*^9, { 3.501279128414*^9, 3.501279130367*^9}, 3.501279218808*^9, { 3.5012793983529997`*^9, 3.5012793984960003`*^9}, {3.5012794331429996`*^9, 3.501279437301*^9}, {3.5012797448599997`*^9, 3.501279969086*^9}, { 3.501280004203*^9, 3.501280004349*^9}, {3.5012800374119997`*^9, 3.501280048201*^9}, {3.501280089473*^9, 3.501280090717*^9}, { 3.501280438218*^9, 3.501280448447*^9}, {3.501280505224*^9, 3.501280531983*^9}, {3.501280866201*^9, 3.501280935266*^9}, { 3.501281466418*^9, 3.501281493061*^9}, {3.5012823167*^9, 3.501282325399*^9}, {3.504459426514*^9, 3.504459435792*^9}, { 3.5053980533120003`*^9, 3.505398068197*^9}, {3.505398130993*^9, 3.505398142775*^9}, {3.5053994682060003`*^9, 3.5053995177790003`*^9}, { 3.5053995490629997`*^9, 3.50539964151*^9}, {3.505399698766*^9, 3.505399743887*^9}, {3.505399805665*^9, 3.505399962403*^9}, { 3.505400026608*^9, 3.505400047285*^9}, {3.505400081927*^9, 3.5054001960179996`*^9}, {3.505467756096774*^9, 3.5054677572979765`*^9}, 3.5054683907370815`*^9, {3.5059260381099997`*^9, 3.5059260497279997`*^9}, { 3.50592613505*^9, 3.505926141148*^9}, {3.505926909517*^9, 3.50592691059*^9}, {3.505927311321*^9, 3.50592731326*^9}, { 3.5062468416304626`*^9, 3.506246859040093*^9}, {3.506248006172493*^9, 3.5062480445641603`*^9}, {3.5062482339640903`*^9, 3.5062483488270903`*^9}, {3.506248449244466*^9, 3.5062484559836774`*^9}, 3.5062485179313855`*^9, 3.506248656537627*^9, {3.5062487491081886`*^9, 3.5062488568887763`*^9}, {3.5062490619511337`*^9, 3.5062491419168735`*^9}, {3.506249182476944*^9, 3.5062491856749496`*^9}, { 3.5062493058263593`*^9, 3.5062493168087783`*^9}, 3.506470266495679*^9, { 3.5065039485619936`*^9, 3.506503955129605*^9}}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`alpha$$ = 1, $CellContext`len$$ = 1.37, $CellContext`mirror$$ = False, $CellContext`nSides$$ = 4, $CellContext`p$$ = "Cube", $CellContext`rad$$ = 0.634, $CellContext`rot$$ = 124.5, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`rad$$], 0.2}, 0.001, 2}, {{ Hold[$CellContext`len$$], 1}, 0.001, 5}, {{ Hold[$CellContext`rot$$], 0}, -180, 180}, {{ Hold[$CellContext`nSides$$], 4}, 3, 24, 1}, { Hold[$CellContext`p$$], { "Cube", "Dodecahedron", "Tetrahedron", "TruncatedIcosahedron"}}, {{ Hold[$CellContext`alpha$$], 1}, 0.1, 10}, { Hold[$CellContext`mirror$$], {False, True}}}, Typeset`size$$ = { 360., {178., 182.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`rad$622$$ = 0, $CellContext`len$623$$ = 0, $CellContext`rot$624$$ = 0, $CellContext`nSides$625$$ = 0, $CellContext`p$626$$ = 0, $CellContext`alpha$627$$ = 0, $CellContext`mirror$628$$ = False}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`alpha$$ = 1, $CellContext`len$$ = 1, $CellContext`mirror$$ = False, $CellContext`nSides$$ = 4, $CellContext`p$$ = "Cube", $CellContext`rad$$ = 0.2, $CellContext`rot$$ = 0}, "ControllerVariables" :> { Hold[$CellContext`rad$$, $CellContext`rad$622$$, 0], Hold[$CellContext`len$$, $CellContext`len$623$$, 0], Hold[$CellContext`rot$$, $CellContext`rot$624$$, 0], Hold[$CellContext`nSides$$, $CellContext`nSides$625$$, 0], Hold[$CellContext`p$$, $CellContext`p$626$$, 0], Hold[$CellContext`alpha$$, $CellContext`alpha$627$$, 0], Hold[$CellContext`mirror$$, $CellContext`mirror$628$$, False]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> ($CellContext`v = N[ Part[ PolyhedronData[$CellContext`p$$, "Edges"], 1]]; $CellContext`e = Part[ Part[ PolyhedronData[$CellContext`p$$, "Edges"], 2], 1]; $CellContext`g = Graphics3D[{ $CellContext`sticks[$CellContext`nSides$$, $CellContext`rad$$, \ $CellContext`len$$, $CellContext`rot$$, $CellContext`alpha$$], If[$CellContext`mirror$$, $CellContext`sticks[$CellContext`nSides$$, $CellContext`rad$$/ 2, $CellContext`len$$, -$CellContext`rot$$, \ $CellContext`alpha$$], {}]}, Boxed -> False, SphericalRegion -> True]), "Specifications" :> {{{$CellContext`rad$$, 0.2}, 0.001, 2}, {{$CellContext`len$$, 1}, 0.001, 5}, {{$CellContext`rot$$, 0}, -180, 180, Appearance -> "Labeled"}, {{$CellContext`nSides$$, 4}, 3, 24, 1, Appearance -> "Labeled"}, {$CellContext`p$$, { "Cube", "Dodecahedron", "Tetrahedron", "TruncatedIcosahedron"}}, {{$CellContext`alpha$$, 1}, 0.1, 10}, {$CellContext`mirror$$, {False, True}}}, "Options" :> {}, "DefaultOptions" :> {}], ImageSizeCache->{405., {309., 314.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellChangeTimes->{ 3.5062492389022427`*^9, {3.506249271131899*^9, 3.5062492864979258`*^9}, 3.506249325794394*^9, {3.506249479439062*^9, 3.506249506598709*^9}, 3.506249546285178*^9, 3.5062527666042547`*^9, 3.5064702707856865`*^9, 3.506503995299675*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Export", "[", RowBox[{"\"\\"", ",", "g"}], "]"}]], "Input", CellChangeTimes->{{3.49956322501*^9, 3.4995632371289997`*^9}, { 3.5003397308034*^9, 3.5003397334086*^9}, {3.50080623948*^9, 3.5008062422530003`*^9}, {3.505397213499*^9, 3.505397222584*^9}, { 3.505925407417*^9, 3.505925415484*^9}, {3.505927564285*^9, 3.505927569751*^9}, {3.506026706532*^9, 3.506026707233*^9}, 3.506026745792*^9, {3.506253437764224*^9, 3.5062534382478256`*^9}}], Cell[BoxData["\<\"stick-demo.stl\"\>"], "Output", CellChangeTimes->{3.499563239381*^9, 3.499988271936823*^9, 3.5003397401166*^9, 3.500806244625*^9, 3.5008486472349997`*^9, 3.5009978606870003`*^9, 3.505401200317*^9, 3.505925418466*^9, 3.505927580972*^9, 3.506026715907*^9, 3.506026747483*^9, 3.50625344099343*^9, 3.506470833962269*^9}] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{1127, 753}, WindowMargins->{{3, Automatic}, {Automatic, 0}}, FrontEndVersion->"8.0 for Microsoft Windows (64-bit) (November 7, 2010)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[567, 22, 163, 2, 83, "Title"], Cell[733, 26, 259, 5, 47, "Text"], Cell[CellGroupData[{ Cell[1017, 35, 155, 2, 36, "Subsection"], Cell[CellGroupData[{ Cell[1197, 41, 12467, 325, 652, "Input"], Cell[13667, 368, 4064, 76, 640, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[17768, 449, 500, 8, 31, "Input"], Cell[18271, 459, 347, 5, 30, "Output"] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)