Saturday, August 12, 2017

Platonic Solids

A regular polygon is a polygon that has all congruent angles and all congruent sides.  For example, a square is a regular polygon because it has 4 congruent angles and 4 congruent sides, and an equilateral triangle is a regular polygon because it has 3 congruent angles and 3 congruent sides. 

A Platonic solid, or a regular convex polyhedron, is a three-dimensional convex solid that has identical regular polygons for each face.  For example, a cube is a Platonic solid because it has 6 identical square faces.  There are five possible Platonic solids in all: the tetrahedron, the cube, the octahedron, the dodecagon, and the icosahedron.  These five Platonic solids have been known for thousands of years.
  
Platonic Solids (Wikipedia)

Finding all the different possible Platonic solids is a great exercise in logic.  First of all, there must be more than 2 faces around a single vertex, because otherwise a three-dimensional object will not be formed.  Secondly, the angle sum of each interior face angle around a single vertex must be less than 360°.  It cannot be more than 360°, because otherwise not all the polygons can fit, nor can it be equal to 360°, because otherwise a three-dimensional object will not be formed.  For example, since each interior angle of an equilateral triangle is 60°, 6 equilateral triangles around a single vertex would form a two-dimensional tiled surface, because 6 · 60° = 360°, and 7 (or more) equilateral triangles would not fit around a single vertex because 7 · 60° > 360°.  Therefore, only 3, 4, or 5 triangles can share a single vertex and form a polyhedron – the tetrahedron, the octahedron, and the icosahedron

Platonic Solid Vertex Defects (Wikipedia)

Similarly, since each interior angle of a square is 90°, 4 squares around a single vertex would form a two-dimensional surface, because  4 · 90° = 360°, and 5 (or more) squares would not fit around a single vertex because 5 · 90° > 360°.  Therefore, only 3 squares can share a single vertex and form a polyhedron – the cube.  Also, since each interior angle of a regular pentagon is 108°, 4 (or more) regular pentagons would not fit around a single vertex because 4 · 108° > 360°.  Therefore, only 3 regular pentagons can share a single vertex and form a polyhedron – the dodecahedron.  Since each interior angle of a regular hexagon is 120°, 3 regular hexagons around a single vertex would form a two-dimensional surface, because  3 · 120° = 360°, and 4 (or more) regular hexagons would not fit around a single vertex because 4 · 120° > 360°.  Therefore, no regular hexagons can be used to form a polyhedron.  Since each interior angle of a regular heptagon, octagon, or larger polygon is greater than 121°, 3 (or more) regular heptagons, octagons, or larger polygons would not fit around a single vertex because 3 · 121° > 360°.  Therefore, no other regular polygon can be used to form a polyhedron, making the tetrahedron, the cube, the octahedron, the dodecagon, and the icosahedron the only possible Platonic solids.

Properties of Platonic Solids

When looking at the different properties of Platonic solids, it is helpful to describe each one with its Schläfli symbol {n, m}, where n is the number of sides of each face, and m is the number of faces around each vertex.  For example, the Schläfli symbol for a cube is {4, 3}, because each face has 4 sides and there are 3 squares around each vertex.  The Schläfli symbol for the tetrahedron is {3, 3}, the octahedron {3, 4}, the dodecagon {5, 3}, and the icosahedron {3, 5}.

Using the above variables n and m, as well as a new variable F representing the total number of faces in the polyhedron, more properties of Platonic solids can be expressed.  Since each face has n number of edges, and each edge is shared by exactly 2 faces, then the total number of edges in the polyhedron is

E = n·F/2

For example, a cube is made up of 6 squares, so F = 6 and n = 4, but each edge is shared by 2 squares, so the total number of edges is E = n·F/2 = 4·6/2 = 12.  

Additionally, since each face has n number of vertices, and each vertex is shared by exactly m faces, then the total number of vertices in the polyhedron is

V = n·F/m

For example, a cube is made up of 6 squares, so F = 6 and n = 4, but each vertex is shared by 3 squares, so the total number of vertices is V = n·F/m = 4·6/3 = 8.

By substituting E and V into Euler’s polyhedral formula

V + F = E + 2

and simplifying, F can be written as a function of n and m, and after that so can E and V.

01
V + F = E + 2
Euler’s polyhedral formula
02
n·F/m + F = n·F/2 + 2
substitution
03
2nF + 2mF = mnF + 4m
multiply by 2m
04
2nF + 2mF – mnF = 4m
subtract mnF
05
F(2n + 2m – mn) = 4m
factor F
06
F = 4m/(2n + 2m – mn)
divide by 2n + 2m – mn

Therefore,

F = 4m/(2n + 2m – mn)

For example, a cube has 3 squares around a single vertex, so n = 4 and m = 3, and therefore must have F = 4m/(2n + 2m – mn) = 4·3/(2·4 + 2·3 – 3·4) = 12/2 = 6 faces.

Substituting F into E, E = n·F/2 = n·4m/2(2n + 2m – mn) = 2mn/(2n + 2m – mn), so

E = 2mn/(2n + 2m – mn)

For example, a cube has 3 squares around a single vertex, so n = 4 and m = 3, and therefore must have E = 2mn/(2n + 2m – mn) = 2·4·3/(2·4 + 2·3 – 3·4) = 24/2 = 12 edges.

Substituting F into V, V = n·F/m = n·4m/m(2n + 2m – mn) = 4n/(2n + 2m – mn), so

V = 4n/(2n + 2m – mn)

For example, a cube has 3 squares around a single vertex, so n = 4 and m = 3, and therefore must have V = 4n/(2n + 2m – mn) = 4·4/(2·4 + 2·3 – 3·4) = 16/2 = 8 vertices.

Using the above formulas:

Solid
Schläfli
Faces
Edges
Vertices
tetrahedron
{3, 3}
4
6
4
cube
{4, 3}
6
12
8
octahedron
{3, 4}
8
12
6
dodecahedron
{5, 3}
12
30
20
icosahedron
{3, 5}
20
30
12

Dual Pairs

From the above formulas and chart, it is apparent that there are some symmetric properties to the five Platonic solids.  The cube and the octahedron are called a dual pair because they have the same number of edges (12), swapped Schläfli symbols ({4, 3} and {3, 4}), and swapped number of faces and vertices (6 and 8).  Similarly, the dodecahedron and the icosahedron are also called a dual pair because they have the same number of edges (30), swapped Schläfli symbols ({5, 3} and {3, 5}), and swapped number of faces and vertices (12 and 20).  The same symmetric properties are true for a tetrahedron and another tetrahedron, so the tetrahedron is called self-dual.

Because the number of faces and vertices are swapped for a dual pair of polyhedra, any polyhedron can be placed exactly inside its dual twin so that each vertex of the inner polyhedron touches the center of a face of the outer polyhedron.

Nested Dual Polyhedra (linkedin)

A dual pair of polyhedra can also be infinitely nested inside each other, alternating every other one.

Nested Cubes and Octahedra (Wikipedia)

The symmetric properties of dual polyhedra can be explained by the formulas for the number of faces, edges, and vertices that were mentioned above.  Dual polyhedra have swapped Schläfli symbols, meaning m (the number of faces around each vertex) and n (the number of sides of each face) are switched.  Switching m and n in the formula for the number of faces F = 4m/(2n + 2m – mn) results in 4n/(2m + 2n – nm), which simplifies to the formula for the number of vertices V = 4n/(2n + 2m – mn), and switching m and n in the formula for the number of vertices V = 4n/(2n + 2m – mn) results in 4m/(2m + 2n – nm), which simplifies to the formula for the number of faces F = 4m/(2n + 2m – mn). This proves that swapped Schläfli symbols in dual polyhedra necessarily results in swapped number of faces and vertices.  Furthermore, switching m and n in the formula for the number of edges E = 2mn/(2n + 2m – mn) results in 2nm/(2m + 2n – nm), which simplifies to itself, E = 2mn/(2n + 2m – mn).  This proves that swapped Schläfli symbols in dual polyhedra necessarily results in the same number of edges. 

The formula for the number of edges in a polyhedra E = 2mn/(2n + 2m – mn) can also be rearranged algebraically as the sum of reciprocals.  Finding the reciprocal of E yields 1/E = (2n + 2m – mn)/2mn, and dividing out each term results in 1/E = 1/m + 1/n1/2, and adding ½ to each side yields the rather elegant equation

1/E + 1/2 = 1/m + 1/n

Or, written with negative exponents,

E-1 + 2-1 = m-1 + n-1

Examples of Platonic Solids

Platonic solids can be found both naturally and artificially.  Some chemical compounds, including crystals, form Platonic solids.  The skeletons of different radiolarian protozoa are shaped as different Platonic solids, including the octahedron, the icosahedron, and the dodecahedron.  In addition, the outer shells of several viruses form Platonic solids, such as the icosahedron-shaped HIV virus.

Circogonia Icosahedra, a Species of Radiolaria (Wikipedia)

There are also plenty of examples of artificially made Platonic solids.  The Rubik’s cube is obviously a cube, but variations of it exist that include the tetrahedron and dodecahedron.  Most dice used in board games are cubes, but there are also dice shaped like tetrahedra, octahedra, dodecahedra, and icosahedra.

Dice Shaped as Platonic Solids

And although not a true Platonic solid because it consists of two different regular polygons, the familiar soccer ball (or football) pattern of hexagons and pentagons is actually a truncated icosahedron.  The 12 pentagons formed were originally the 12 vertices of the icosahedron, and the 20 hexagons formed were originally the 20 triangular faces of the icosahedron.

Truncating an Icosahedron (“How to Make a Soccer Ball”)

It is also worth mentioning that there are only two instances in the Bible where any Platonic solid is described, and both are cubes.  The first cube can be inferred from the description of the Most Holy Place of the temple in 1 Kings 6:20, “The inner sanctuary was twenty cubits long, twenty cubits wide, and twenty cubits high, and [Solomon] overlaid it with pure gold.”  The second cube can be inferred from the description of the New Jerusalem in Revelation 21:16, “The city lies foursquare, its length the same as its width. … Its length and width and height are equal.”  The description of the same shape links the two places; the Most Holy Place in the temple and the New Jerusalem are both the dwelling place of the Most High God.

Conclusion

The simple parameter of the Platonic solid, a convex solid that has identical regular polygons for each face, yields only five different possible polyhedra: the tetrahedron, the cube, the octahedron, the dodecagon, and the icosahedron.  Each Platonic solid follows a formula for the number of faces, edges, and vertices, and have symmetric dual properties.  Lastly, Platonic solids can be found both in nature and in man-made objects, as well as in the Bible.

Saturday, August 5, 2017

PiGRRL Zero Plus Tutorial


This past summer, my 12-year-old son and I decided to build a handheld video game system called a PiGRRL Zero Plus that runs on a Raspberry Pi Zero.  Considering we had little experience with soldering and small electrical parts, this was a challenging yet rewarding project.  This tutorial is a compilation of the many hours of work and research we did that hopefully someone else will find useful.

Resources
-          There are some helpful videos and downloads on Thingiverse by JPete24 found here.  He also sells cases on Etsy if you don’t have a 3D printer.  You will also need the pdf download of separate instructions found here.
-          There is also a helpful tutorial for the PiGrrl Zero (not Plus) found here.  It is not quite what is needed for the Plus, though, but close enough to be helpful.  (Don’t download the software support packages, though.)

Initial Setup
-          Write the PiGrrl Zero Plus image file (download from here or here) onto the SD card using Win32DiskImager
 
-          For troubleshooting the screen, you can also use the Jessie Lite-based PiTFT 2.8” Resistive Image (download from here) which should work “out of the box”
-          When re-writing an image over the SD card, clear the partitions and format the card first by following the steps listed on the second suggestion found here (the suggestion that uses diskpart in the command prompt):
-           The command line procedure is not simple, but it is the most likely thing to work.
-           When re-formatting the "drive" you're actually only formatting a partition on the drive. You need to use the diskpart utility to remove the partitions and create 1 single partition covering the full volume.
-           diskpart can be a bit dangerous, because if you pick the wrong disk or partition, you can remove data or partitions that are extremely, EXTREMELY important and lose all data on your machine.
-           Proceed with extreme caution!
-           Open up a command prompt as administrator (open the start menu, type cmd and press Enter.)
-           Type diskpart and press Enter. You'll end up with a new prompt that looks like this:
-           DISKPART>
-           Type
-           list disk <ENTER>
-           and you'll get a listing of all drives on your machine.
-           Type
-           select disk # <ENTER>
-           to select a disk, where # is the number of the disk Windows screw-balled. Usually, the device is disk 1, but it's always best to make sure.
-           Then type
-           list partition <ENTER>
-           to get a listing of all partitions on the disk.
-           If you're sure you have the right disk/partition, you can then repeat typing
-           select partition # <ENTER>
-           delete partition <ENTER>
-           until all partitions are removed from that drive.
-           Once the drive is empty, exit diskpart and remove the drive. Wait at least 5 minutes, then re-insert the drive. DO NOT CLICK FORMAT – this will most likely re-create the problem. Instead, enter diskpart again, and select the disk. Then type
-           create partition primary <ENTER>
-           Once you have created the partition, exit diskpart and, in the command promt, type
-           diskmgmt.msc <ENTER>
-           This will provide a reliable way to create a FAT32 partition. On the drive you would like to format (NEVER TOUCH DISK 0!), right click and select format. The allocation unit size option should be default, and the File System option should be set to FAT32. The format may take a while, depending on the disk size, be patient.
-           This should fix partition troubles on any readable USB flash drive.
-          Insert the card in the Pi Zero, use the dual male header to connect the 3.2” PiTFT screen to the Pi Zero (use some poster putty to wedge the Pi Zero and header for a temporary solderless connection), connect a USB hub with a keyboard and wireless connector, and connect the power supply and plug it in to turn it on
-          Don’t put the Pi Zero in upside down!  When the PiTFT screen is facing away from you, the mostly green side of the Pi should be facing towards you.
-          If all goes well, a green light will flash on the Pi Zero, the screen will start out white for about 10 seconds, then turn black, and eventually load Retropie.  This usually takes about 30 seconds.
-          The PiGrrl Zero (not Plus) tutorial pdf instructs you to download PiTFT Support and other things.  There is no need to do this!  The PiGrrl Zero image will already work without PiTFT support.
-          Use the left/right arrows to find RetroPie, hit “X” to select it, use the up/down arrows to find “config wifi”, hit “X” to select it, and follow the on-screen instructions to connect your Pi Zero to your wi-fi
-          Use PuTTY (download from here) to conveniently SSH into your Pi Zero from a computer on the same wifi network.  After opening PuTTY, type in the hostname of “retropie.local” and click “Open”.  A new window should open up and ask for credentials.  After you input the user name of “pi” and a password of “raspberry”, you will gain access to the Raspberry Pi command line.
 
-          In the Raspberry Pi command line (via PuTTY), type “sudo nano /boot/config.txt” to open up the config file.  On the last line of the file, add “display_rotate=2”, press “Ctrl+X” to exit, and save changes on the way out.  This will turn the screen display 180° which is necessary for the PiGrrl Zero Plus.  In the Raspberry Pi command line, type “sudo reboot” to reboot the Pi to test this.
-          To use all the memory on your SD card, expand the file system by typing “sudo raspi-config” in the Raspberry Pi command line, choose “Expand File System”, follow any directions, and reboot.
 
-          To upload roms (and remove pre-installed roms), turn on the Pi Zero Plus, make sure it is connected wirelessly, go to a computer with Windows, open up File Manager, and type “\\RETROPIE” in the address bar.  Choose the “ROMS” folder and copy and paste the new ROM in the appropriate system folder.
-          Sometimes I would get the error message “Windows cannot access Retropie”.  On the Pi Zero Plus, go to “RetroPie” and then “Config WiFi”, get the IP address, and type that in the windows address bar in place of “RETROPIE”.  For example, “\\192.168.1.67”.
-          The Pi Zero is not powerful enough to run N64 (or higher) roms.
-          The Gameboy Advance emulator needs an additional file called “gba_bios.bin” copied in the RetroPie/BIOS folder for its games to work.  The file can be downloaded from many websites (such as here) and one way to copy it over is to go to File Manager in Windows, type “\\RETROPIE\bios” in the address bar, and paste the file there.
-          To change the look of the Retropie menu, go to Retropie, and choose “install emulation station theme” and follow the instructions to download and install.  (My favorite is “Simple Dark”.)  Then restart EmulationStation, go to “UI Settings” on the main menu, and scroll down to “Themes” and pick your theme.
-          Sometimes the font size for a theme is too small for the PiTFT screens (like “Simple Dark” on a 3.2” PiTFT).  To make the font size bigger on a theme, go to the command line, and type “sudo nano /etc/emulationstation/themes/carbon/carbon.xml” (or whatever the name of the theme is) and change all font-size to 0.05 (so that each line with “fontSize” it looks like “<fontSize>0.05</fontSize>”).

Screen
-          Now that everything is working, unhook the PiTFT and use some heavy duty wire cutters to clip off the 2x20 female pins and the other set of 2x16 pins, and solder all 40 points of the dual male header to where the 2x20 female pins used to be.  Place some masking tape on the other set of unused pins to prevent short circuits.  Use a multimeter to test your soldering connections.
-          Cut trace Pin #18 on the PiTFT circuit board.  Use a multimeter to make sure it is cut.
-          Solder the Pi to the other side of the male dual header.  Once again, make sure it is put in the right way: when the PiTFT screen is facing away from you, the mostly green side of the Pi should be facing towards you.  Use a multimeter to test your soldering connections.
-          Turn on the Pi to make sure the screen is working before moving on to the next step

Battery
-          Solder wires to the battery circuit board, switch and Pi Zero GPIO pins exactly as described here.  You will need to snap off the female USB jack off of the battery circuit board and save it for the USB step.
-          Connect the battery to the circuit board and test everything out by turning on the Pi with the battery before moving on to the next step.

Buttons
-          Solder all buttons on the button gamepad (described here). 
-          Also solder the four buttons for the PiTFT that are on the front beside the screen.
-          Solder wires from the two button gamepads (B1, B2, B3, B4, ground) and the two shoulder buttons (but not the TFT buttons) to the appropriate GPIO pin on the Pi Zero.  Use the diagram found here.
-          Since the Pi Zero is upside down and rotated inside the case, I used this modified image to help me (battery ground, battery 5V added; start, select, and TFT buttons not needed):

-          I also used some of the available “ground” pins for grounding the button and audio components
-          It’s also helpful to use different color wires and write down which colors went where to help troubleshoot for later on
-          Use a multimeter to test all your connections.
-          Once soldered, wrap the metal parts of the shoulder buttons with some masking or painter’s tape to prevent accidentally short circuits.
-          Turn on the Pi to make sure the buttons are working before moving on to the next step.  You will probably need to play a game or two (or three or ten) to test this out properly.  (The top TFT button is “Select” and the second TFT button is “start”)

USB
-          Solder wires from the USB OTG adapter to the female USB jack (from the battery circuit board) exactly as described here
-          I could never get this step to work out properly.  The keyboard would work but not the USB hub or wireless (maybe a power issue?)  I bought a $5 micro USB to female USB adapter from Amazon, cut the plastic off the female USB and melted some of the plastic on the case to make it fit in the right spot.
-          Connect a USB device (the hub with keyboard and wireless connector) and turn on the Pi to test your USB wire out before moving on to the next step.

Audio
-          Solder wires from the speaker, potentiometer, and audio circuit board as pictured in the 2nd page of this pdf file
-          I did not need to connect SD to 5V (Vin to 5V was enough)
-          I have no idea how to “bridge between gain and GND” so I did not do that, either
-          Turn on the Pi, load up a game (or two or twenty) to test out the sound before moving on to the next step
-          Maybe it was just my poor soldering skills, but I found the audio to be very finicky and the potentiometer to die out if the volume was maxed out for extended periods of time.
-          Also, the volume knob only works from 90% to 100% (there were several other online reports of this, too)
-          Expect retro sound quality.

Putting Everything Together
-          Tap each screw hole of the case with a tap set.  Screw the tap bit in the hole until it “bites” (a few turns), and then alternate between doing ¾ of a turn right and ¼ of a turn back.  When you have gone far enough, unscrew the tap bit until it comes out of the hole.
-          Screen: Put the four 3D printed TFT buttons in the appropriate holes and balance the case on top of two equally wide books on each side so the buttons can hang down.  Peel the plastic protector off of the screen and place the screen in the appropriate place, lining the screw holes up.  Screw the four screws in to hold the screen in place.
-          I needed a little more wiggle room to install these, so I actually took the soldering gun and melted some of the inside of the case to make more room
-          Buttons: Put the 3D printed D-Pad and 3D printed A, B, X, Y button pad in the appropriate holes and balance the case on top of two equally wide books on each side so the buttons can hang down.  Line the button pads with their two screw holes and screw those in place.
-          I needed a little more wiggle room to install these, so I actually took the soldering gun and melted some of the inside of the case to make more room
-          Don’t screw in the screws all the way or the buttons will stay in the down position.  The button pads will probably not be level.
-          Audio: Place the speaker in the appropriate hole and use a little bit of tape to hold it in place.  Place the potentiometer in the appropriate place and use a little bit of poster putty to hold it in place (or if you are feeling confident use a hot glue gun).  Whatever you use, make sure that you can still spin the potentiometer after you put it in!  Then place the audio circuit board in the top right of the same case and use some poster putty to hold it in place.
-          Battery: Place the battery circuit board in the appropriate place (there are four protrusions to hold it in place), the battery switch in the appropriate place, and the battery in the top middle of the same case.  Use poster putty to hold each part in place.
-          USB: Place the female USB jack in the appropriate place and use some poster putty to hold it in place.
-          Turn on the Pi and test everything out before screwing the two sides of the case together.  If everything works, use some masking or painter’s tape to cover any putty (otherwise wires from the other side stick to them) and any metal parts (so nothing short circuits), place the shoulder buttons and 3D printed shoulder buttons in the appropriate place, put the two sides of the case together, and screw the four screws in place.
-          Enjoy your Pi Zero Plus!