Python for Everyone!
Oregon Curriculum Network

Polyhedrons¶

Polyhedrons make a great entry point into mathematics, because they're not only pretty to look at, they're graphs (as in Graph Theory), a kind of data structure, made of nodes and edges. The edges border openings we call "faces" though in wireframe polys, these may be more like "windows", not filled in.

Here in Oregon, we have the legal right to introduce a scheme of nested polyhedrons of more whole number volumes than you may be expecting. Consider this table:

 Shape Volume Scale Tetrahedron 1.0000 1.0000 Cuboctahedron 2.5000 0.5000 Icosahedron 1 ~2.9180 ~0.5402 Duo-Tet Cube 3.0000 1.0000 Octahedron 4.0000 1.0000 Rhombic Triacontahedron 5.0000 ~0.9995 Rhombic Triacontahedron 2 ~5.0078 1.0000 Pentagonal Dodecahedron 3 5.4271 ~0.7071 Rhombic Dodecahedron 4 6.0000 1.0000 Pentagonal Dodecahedron 5 ~15.3500 1.0000 Icosahedron ~18.5123 1.0000 Cuboctahedron 20.0000 1.0000 Duo-Tet Cube 24.0000 2.0000 1 faces flush with volume 4 octahedron's 2,4 "shrink-wrapped" around unit-radius sphere 3 face diagonals = edges of volume 3 cube 5 structural dual of Icosa (Icosa = jitterbugged Cubocta)

Now lets take a look at what these look like, minus a few to keep the picture uncluttered: We can pull up the coordinates for these polyhedrons from an SQL database. Polyhedrons give us an entry point into databases as well. We could use a Graph Database, such as Neo4j, but lets stick with a language called SQL.

In :
import sqlite3 as sql
import os
from pprint import pprint

class DB:
backend  = 'sqlite3'       # default
target_path = os.getcwd()  # current directory
db_name = ":file:"         # lets work directly with a file
db_name = os.path.join(target_path, 'shapes_lib.db')

@classmethod
def connect(cls):
if cls.backend == 'sqlite3':
DB.conn = sql.connect(DB.db_name)
DB.c = DB.conn.cursor()
elif cls.backend == 'postgres': # or something else
DB.conn = sql.connect(host='localhost',
user='root', port='8889')
DB.c = DB.conn.cursor()

@classmethod
def disconnect(cls):
DB.conn.close()

DB.connect()
DB.c.execute("SELECT poly_long, poly_color, poly_volume from Polys") # query
pprint(DB.c.fetchall()) # print results
DB.disconnect()
[('Tetrahedron', 'Orange', 1.0),
('Inverse Tetrahedron', 'Black', 1.0),
('Cube', 'Green', 3.0),
('Octahedron', 'Red', 4.0),
('Rhombic Dodecahedron', 'Blue', 6.0),
('Cuboctahedron', 'Yellow', 20.0)]

The DB class contains information for connecting to a SQLite database, which may be accessed directly, as a text file, no need for a special server. SQLite is free of charge.

The database was created earlier.

What we see above is connecting to the database, running a one-liner, a SELECT query, and pretty-printing the results. Then disconnecting.

These volumes are whole numbers. Lets look at their coordinates.

In :
DB.connect()
DB.c.execute("SELECT vertex_label, coord_a, coord_b, coord_c, coord_d FROM Coords ORDER BY vertex_label") # query
pprint(DB.c.fetchall()) # print results
DB.disconnect()
[('A', 1.0, 0.0, 0.0, 0.0),
('B', 0.0, 1.0, 0.0, 0.0),
('C', 0.0, 0.0, 1.0, 0.0),
('D', 0.0, 0.0, 0.0, 1.0),
('E', 0.0, 1.0, 1.0, 1.0),
('F', 1.0, 0.0, 1.0, 1.0),
('G', 1.0, 1.0, 0.0, 1.0),
('H', 1.0, 1.0, 1.0, 0.0),
('I', 1.0, 1.0, 0.0, 0.0),
('J', 1.0, 0.0, 1.0, 0.0),
('K', 1.0, 0.0, 0.0, 1.0),
('L', 0.0, 1.0, 1.0, 0.0),
('M', 0.0, 1.0, 0.0, 1.0),
('N', 0.0, 0.0, 1.0, 1.0),
('O', 2.0, 1.0, 1.0, 0.0),
('P', 2.0, 1.0, 0.0, 1.0),
('Q', 1.0, 2.0, 1.0, 0.0),
('R', 1.0, 2.0, 0.0, 1.0),
('S', 1.0, 0.0, 2.0, 1.0),
('T', 1.0, 0.0, 1.0, 2.0),
('U', 0.0, 1.0, 2.0, 1.0),
('V', 0.0, 1.0, 1.0, 2.0),
('W', 1.0, 1.0, 2.0, 0.0),
('X', 0.0, 2.0, 1.0, 1.0),
('Y', 1.0, 1.0, 0.0, 2.0),
('Z', 2.0, 0.0, 1.0, 1.0)]

Why are these coordinates integers and why are there four of them per labeled vertex? Is this another "legal in Oregon" thing?

These are Quadray Coordinates, which you may read more about on Wikipedia.

Here's a diagram giving a sense of what letters go with what shapes: Converting to XYZ is pretty easy, especially with a computer.

Lets see those 26 vertexes in XYZ coordinates instead:

In :
DB.connect()
DB.c.execute("SELECT vertex_label, coord_x, coord_y, coord_z FROM Coords ORDER BY vertex_label") # query
pprint(DB.c.fetchall()) # print results
DB.disconnect()
[('A', 0.35355339059327373, 0.35355339059327373, 0.35355339059327373),
('B', -0.35355339059327373, -0.35355339059327373, 0.35355339059327373),
('C', -0.35355339059327373, 0.35355339059327373, -0.35355339059327373),
('D', 0.35355339059327373, -0.35355339059327373, -0.35355339059327373),
('E', -0.35355339059327373, -0.35355339059327373, -0.35355339059327373),
('F', 0.35355339059327373, 0.35355339059327373, -0.35355339059327373),
('G', 0.35355339059327373, -0.35355339059327373, 0.35355339059327373),
('H', -0.35355339059327373, 0.35355339059327373, 0.35355339059327373),
('I', 0.0, 0.0, 0.7071067811865475),
('J', 0.0, 0.7071067811865475, 0.0),
('K', 0.7071067811865475, 0.0, 0.0),
('L', -0.7071067811865475, 0.0, 0.0),
('M', 0.0, -0.7071067811865475, 0.0),
('N', 0.0, 0.0, -0.7071067811865475),
('O', 0.0, 0.7071067811865475, 0.7071067811865475),
('P', 0.7071067811865475, 0.0, 0.7071067811865475),
('Q', -0.7071067811865475, 0.0, 0.7071067811865475),
('R', 0.0, -0.7071067811865475, 0.7071067811865475),
('S', 0.0, 0.7071067811865475, -0.7071067811865475),
('T', 0.7071067811865475, 0.0, -0.7071067811865475),
('U', -0.7071067811865475, 0.0, -0.7071067811865475),
('V', 0.0, -0.7071067811865475, -0.7071067811865475),
('W', -0.7071067811865475, 0.7071067811865475, 0.0),
('X', -0.7071067811865475, -0.7071067811865475, 0.0),
('Y', 0.7071067811865475, -0.7071067811865475, 0.0),
('Z', 0.7071067811865475, 0.7071067811865475, 0.0)]

The database in question consists of three tables: Polys, Faces, and Coords. A polyhedron is defined in terms of its faces, such as ('A', 'B', 'C') which would consist of the three edges connecting 'A' to 'B', 'B' to 'C' and 'C' back to 'A'. From faces, a computer deduces edges. Edges terminate in labeled points, for which the database stores coordinates.