Cross Sections of Regular Polyhedra
Cross Sections of Regular Polyhedra
CrossSectionPolygon[hedr_,{p1_,p2_,p3_}]:=Module[{eq,edgeeq,pts,c,sol,x,y,z,t},eq=Det[{#-#2,#3-#2,#4-#2}]&;If[Chop@Norm@Cross[p2-p1,p3-p1]0,Return[{{}}]];edgeeq=Cases[Normal@PolyhedronData[hedr,"Edges"],Line@{pt1_,pt2_}(pt2-pt1)t+pt1,-1];sol=Quiet[NSolve[eq[{x,y,z},p1,p2,p3]0&&#{x,y,z},{x,y,z,t}]&/@edgeeq];sol=Select[sol,#=!={}&&!TrueQ[(t/.#〚1〛)<0||(t/.#〚1〛)>1]&];pts=Union@Replace[Join@@({x,y,z}/.sol),pt_/;!FreeQ[pt,t]Sequence@@(pt/.{{t0.},{t1.}}),{1}];c=Mean@pts;Polygon@SortBy[pts,With[{v1=Normalize[#-c],v2=Normalize[p1-c]},N@ArcTan[v1.v2,Cross[v1,v2].Cross[Normalize[p3-p2],Normalize[p1-p2]]]]&]]
CrossSectionGraphics[hedr_,{p1_,p2_,p3_}]:=Graphics3D[{{FaceForm[],EdgeForm[AbsoluteThickness[2]],PolyhedronData[hedr]〚1〛},{FaceForm[Directive[Opacity[.85],Black,Glow@LightBlue]],EdgeForm[Darker[Red,.6]],With[{pl=CrossSectionPolygon[hedr,{p1,p2,p3}]},{pl,PointSize[0.025],RGBColor[.49,0,0],Point@@pl}]},{PointSize[.03],Orange,Point@{p1,p2,p3}}},BoxedFalse,RotationAction"Clip",PlotRangePolyhedronData[hedr,"Circumradius"],ViewAnglePi/10,ImageSize{400,350}];
PointConstructor[hedr_,e_,ofs_]:=(#2-#)ofs+#&@@#〚1,#〚2,1,e〛〛&@PolyhedronData[hedr,"Edges"]
Manipulate[CrossSectionGraphics[hedr,{PointConstructor[hedr,e1,ofs1],PointConstructor[hedr,e2,ofs2],PointConstructor[hedr,e3,ofs3]}],Control[{{hedr,"Cube","polyhedron"},{"Tetrahedron""tetrahedron","Cube""cube","Octahedron""octahedron","Dodecahedron""dodecahedron","Icosahedron""icosahedron"},SetterBar[Dynamic[hedr,(hedr=#;{e1,e2,e3}={1,2,3})&],Sequence@@#2]&}],Delimiter,Grid[{{"","edge","position"},{"first point",Control[{{e1,1,""},1,Dynamic@PolyhedronData[hedr,"EdgeCount"],1,Slider,ImageSizeSmall}],Control[{{ofs1,.25,""},0.,1.,Slider,ImageSizeSmall}]},{"second point",Control[{{e2,2,""},1,Dynamic@PolyhedronData[hedr,"EdgeCount"],1,Slider,ImageSizeSmall}],Control[{{ofs2,.5,""},0.,1.,Slider,ImageSizeSmall}]},{"third point",Control[{{e3,3,""},1,Dynamic@PolyhedronData[hedr,"EdgeCount"],1,Slider,ImageSizeSmall}],Control[{{ofs3,.75,""},0.,1.,Slider,ImageSizeSmall}]}},Spacings{2},Alignment{{Left}}],SaveDefinitionsTrue]
Three noncollinear points determine a plane. Fix three points on the edges of a polyhedron and visualize the corresponding cross section. For a cube, the resulting polygon can be a triangle, a quadrilateral, a pentagon, or a hexagon.