home *** CD-ROM | disk | FTP | other *** search
-
- (* Copyright 1989, 1990 Wolfram Research Inc. *)
-
- (*:Version: Mathematica 2.0 *)
-
- (*:Name: Graphcs`Polyhedra` *)
-
- (*:Title: Graphics with Platonic Polyhedra *)
-
- (*:Author: Roman Maeder *)
-
- (*:Keywords:
- Polyhedron, vertices, faces, Stellate,
- Tetrahedron, Cube, Octahedron,
- Dodecahedron, Icosahedron, Hexahedron,
- GreatDodecahedron, SmallStellatedDodecahedron,
- GreatStellatedDodecahedron, GreatIcosahedron
- *)
-
- (*:Requirements: none. *)
-
- (*:Warnings:
- Faces[] and Vertices[] fail on
- GreatDodecahedron, SmallStellatedDodecahedron, and
- GreatStellatedDodecahedron.
- *)
-
- (*:Source:
- Roman E. Maeder: Programming in Mathematica, 2nd Ed.,
- Addison-Wesley, 1991.
- *)
-
- (*:Summary:
- This package plots various Platonic polyhedra. One can also
- access the coordinates of the vertices and the vertex numbers
- of each face of the solids.
- *)
-
-
- BeginPackage["Graphics`Polyhedra`"]
-
- Polyhedron::usage = "Polyhedron[name] gives a Graphics3D object
- representing the specified solid centered at the origin and with
- unit distance to the midpoints of the edges. Polyhedron[name,
- center, size] uses the given center and size. The possible names
- are in the list Polyhedra."
-
- Vertices::usage = "Vertices[name] gives a list of the vertex coordinates
- for the named solid."
-
- Faces::usage = "Faces[name] gives a list of the faces for the named
- solid. Each face is a list of the numbers of the vertices that
- comprise that face."
-
- Stellate::usage = "Stellate[expr, (ratio:2)] replaces each polygon
- in expr by a pyramid with the polygon as its base. Stellation
- ratios less than 1 give concave figures."
-
- Polyhedra::usage = "Polyhedra is a list of the known polyhedra."
-
- Polyhedra = {Tetrahedron, Cube, Octahedron,
- Dodecahedron, Icosahedron, Hexahedron,
- GreatDodecahedron, SmallStellatedDodecahedron,
- GreatStellatedDodecahedron, GreatIcosahedron}
-
- Map[(Evaluate[#]::"usage" =
- StringJoin[ToString[#],
- " is a kind of polyhedron, for use with
- the Polyhedron[] function. See Polyhedron."])&,
- Polyhedra]
-
-
- Begin["`Private`"]
-
- Polyhedron[name_Symbol, opts___ ] :=
- PolyGraphics3D[ Vertices[name], Faces[name], opts ] /;
- MemberQ[Polyhedra, name]
-
- PolyGraphics3D[ vertices_, faces_, pos_:{0.0,0.0,0.0}, scale_:1.0 ] :=
- Graphics3D[ Polygon /@
- Map[scale # + pos &, (vertices[[#]]&) /@ faces, {2}] ]
-
- Norm[ v_ ] := Sqrt[Plus @@ (v^2)]
- Apex[ v_ ] := Plus @@ v / Length[v]
-
- DualFace[ vertex_, faces_ ] :=
- Block[{incident, current, newfaces={}, newface},
- incident = Select[ faces, MemberQ[#, vertex]& ];
- incident = RotateLeft[#, Position[#, vertex][[1,1]]-2]& /@ incident;
- incident = Take[#, 3]& /@ incident;
- current = incident[[1]];
- While[incident =!= {},
- newface = Select[ incident,
- Length[Intersection[#, current]] > 1& ] [[1]];
- AppendTo[ newfaces,
- Position[faces, _List?(Length[Intersection[#, newface]]==3 &)] [[1, 1]] ];
- current = newface;
- incident = Complement[ incident, {current} ];
- ];
- newfaces
- ]
-
- DualFaces[name_] :=
- Block[{i, faces = Faces[name], vertices = Vertices[name]},
- Table[ DualFace[i, faces], {i, Length[vertices]} ]
- ]
-
- DualVertices[name_] :=
- Block[{faces = Faces[name], vertices = Vertices[name],
- dvertices, length1, length2},
- dvertices = Apex /@ (vertices[[#]]&) /@ faces;
- length1 = Norm[ (vertices[[faces[[1,1]]]] +
- vertices[[faces[[1,2]]]])/2 ];
- dvertices = dvertices / length1;
- dvertices = 1/Norm[#]^2 # & /@ dvertices;
- dvertices
- ]
-
- Tetrahedron /: Faces[Tetrahedron] =
- {{1, 2, 3}, {1, 3, 4}, {1, 4, 2}, {2, 4, 3}}
-
- Tetrahedron /: Vertices[Tetrahedron] = N[
- {{0, 0, 3^(1/2)}, {0, (2*2^(1/2)*3^(1/2))/3, -3^(1/2)/3},
- {-2^(1/2), -(2^(1/2)*3^(1/2))/3, -3^(1/2)/3},
- {2^(1/2), -(2^(1/2)*3^(1/2))/3, -3^(1/2)/3}} ]
-
- Hexahedron /: Faces[Hexahedron] =
- {{1, 2, 3, 4}, {1, 4, 6, 7}, {1, 7, 8, 2},
- {2, 8, 5, 3}, {5, 8, 7, 6}, {3, 5, 6, 4}}
-
- Hexahedron /: Vertices[Hexahedron] = N[Sqrt[2]/2] *
- {{1, 1, 1}, {-1, 1, 1}, {-1, -1, 1}, {1, -1, 1},
- {-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}}
-
- Cube/: Faces[Cube] := Faces[Hexahedron]
- Cube/: Vertices[Cube] := Vertices[Hexahedron]
-
- Octahedron /: Faces[Octahedron] =
- {{1, 2, 3}, {1, 3, 5}, {1, 5, 6}, {1, 6, 2},
- {2, 6, 4}, {2, 4, 3}, {4, 6, 5}, {3, 4, 5}}
-
- Octahedron /: Vertices[Octahedron] = N[Sqrt[2]] *
- {{0, 0, 1}, {1, 0, 0}, {0, 1, 0},
- {0, 0, -1}, {-1, 0, 0}, {0, -1, 0}}
-
- SphericalToCartesian[{theta_, phi_}] :=
- {Sin[theta] Cos[phi], Sin[theta] Sin[phi], Cos[theta]}
-
- Icosahedron /: Faces[Icosahedron] =
- {{1, 3, 2}, {1, 4, 3}, {1, 5, 4}, {1, 6, 5}, {1, 2, 6},
- {2, 3, 7}, {3, 4, 8}, {4, 5, 9}, {5, 6, 10}, {6, 2, 11},
- {7, 3, 8}, {8, 4, 9}, {9, 5, 10}, {10, 6, 11}, {11, 2, 7},
- {7, 8, 12}, {8, 9, 12}, {9, 10, 12}, {10, 11, 12}, {11, 7, 12}}
-
- Icosahedron /: Vertices[Icosahedron] :=
- Icosahedron /: Vertices[Icosahedron] =
- N[ N[ (SphericalToCartesian /@
- {{0,0},
- {ArcTan[2], 0}, {ArcTan[2], 2Pi/5}, {ArcTan[2], 4Pi/5},
- {ArcTan[2], 6Pi/5}, {ArcTan[2], 8Pi/5},
- {Pi - ArcTan[2], Pi/5}, {Pi - ArcTan[2], 3Pi/5},
- {Pi - ArcTan[2], 5Pi/5}, {Pi - ArcTan[2], 7Pi/5},
- {Pi - ArcTan[2], 9Pi/5},
- {Pi,0}
- })/(1/2 + Cos[ArcTan[2]]/2)^(1/2),
- 2 Precision[1.0] ]
- ]
-
- Dodecahedron/: Vertices[Dodecahedron] :=
- Dodecahedron/: Vertices[Dodecahedron] =
- DualVertices[Icosahedron]
- Dodecahedron/: Faces[Dodecahedron] :=
- Dodecahedron/: Faces[Dodecahedron] =
- DualFaces[Icosahedron]
-
- GreatDodecahedron/:
- Polyhedron[ GreatDodecahedron, opts___ ] :=
- Stellate[ Polyhedron[Icosahedron, opts], 1/Sqrt[2] ]
-
- SmallStellatedDodecahedron/:
- Polyhedron[ SmallStellatedDodecahedron, opts___ ] :=
- Stellate[ Polyhedron[Dodecahedron, opts], Sqrt[5] ]
-
- GreatStellatedDodecahedron/:
- Polyhedron[ GreatStellatedDodecahedron, opts___ ] :=
- Stellate[ Polyhedron[Icosahedron, opts], 3 ]
-
- AdjacentTo[face_, flist_] :=
- Select[flist, Length[Intersection[face, #]] == 2&]
-
- Opposite[face_, flist_] :=
- Block[ {adjacent, next},
- adjacent = AdjacentTo[ face, flist ];
- next = AdjacentTo[#, flist]& /@ adjacent;
- next = Complement[#, {face}]& /@ next;
- Flatten[ Intersection @@ #& /@ next ]
- ]
-
- GreatIcosahedron/: Vertices[GreatIcosahedron] := Vertices[Icosahedron];
-
- GreatIcosahedron/: Faces[GreatIcosahedron] :=
- GreatIcosahedron/: Faces[GreatIcosahedron] =
- Opposite[#, Faces[Icosahedron]]& /@ Faces[Icosahedron];
-
-
- StellateFace[face_List, k_] :=
- Block[ { apex, n = Length[face], i } ,
- apex = N [ k Apply[Plus, face] / n ] ;
- Table[ Polygon[ {apex, face[[i]], face[[ Mod[i, n] + 1 ]] }
- ],
- {i, n} ]
- ]
-
- Stellate[poly_, k_:2] :=
- Flatten[ poly /. Polygon[x_] :> StellateFace[x, k] ] /;
- NumberQ[N[k]]
-
-
- (* Compatibility with V1.1 Polyhedra.m *)
-
-
- GreatStellatedDodecahedron[opts___] :=
- Polyhedron[GreatStellatedDodecahedron, opts][[1]]
-
- SmallStellatedDodecahedron[opts___] :=
- Polyhedron[SmallStellatedDodecahedron, opts][[1]]
-
- GreatDodecahedron[opts___] := Polyhedron[GreatDodecahedron, opts][[1]]
-
- Dodecahedron[opts___] := Polyhedron[Dodecahedron, opts][[1]]
-
- GreatIcosahedron[opts___] :=
- Polyhedron[GreatIcosahedron, opts][[1]]
-
- Icosahedron[opts___] := Polyhedron[Icosahedron, opts][[1]]
-
- Octahedron[opts___] := Polyhedron[Octahedron, opts][[1]]
-
- Cube[opts___] := Polyhedron[Cube, opts][[1]]
-
- Hexahedron[opts___]:= Polyhedron[Hexahedron, opts][[1]]
-
- Tetrahedron[opts___] := Polyhedron[Tetrahedron, opts][[1]]
-
- End[] (* Graphics`Polyhedra`Private` *)
-
- Protect[ Polyhedron, Stellate, Vertices, Faces ]
-
- EndPackage[] (* Graphics`Polyhedra` *)
-
- (*:Limitations:
- *)
-
- (*:Tests:
- *)
-
- (*:Examples:
-
- Show[ Polyhedron[Dodecahedron] ]
-
- Show[ Polyhedron[ GreatStellatedDodecahedron]]
-
- Vertices[Dodecahedron]
-
- Faces[ Icosahedron ]
-
- Show[ Stellate[ Polyhedron[ Octahedron ] ] ]
-
- *)
-
-