OpenPolyhedra  1.0
Open Polyhedra - set texture coordinates to polyhedra.

This program sets texture coordinates to vertices of the Platonic solids (perfect polyhedra): tetrahedron, octahedron, hexahedron (cube), icosahedron and dodecahedron.

Platonic-Solids-Chart.jpg
Platonic Solids

Main Steps:

  1. Then, it is just a question of mapping the open (flattened) polyhedron onto the texture plane (z=0).
  1. Modeling polyhedra as graphs, one can use any traversal algorithm, e.g., breadth or depth first.
  1. Sort the intersections along the ray (parametrically described).
  2. The one closer to the origin of the ray is from the selected face.
  3. If the polyhedra are convex, there can be only two intersections.
  4. The ray has coordinates (x,y,0) and (x,y,1).
  5. Use gluUnProject to bring the ray back to world coordinates.
  6. It is necessary an algorithm of point in polygon testing (an implementation using winding number is simpler, but one using the even-odd rule is more robust).
  1. Remember that the fixed point of a linear transformation is the origin.
  2. Therefore, choose the edge that will work as a rotation axis, and translate one of its two vertices, to the origin.
  3. Then, apply the rotation and translate it back.

Take a look at drawTexture() for further theoretical reasoning...

See also
https://en.wikipedia.org/wiki/Platonic_solid
https://en.wikipedia.org/wiki/Archimedean_solid

release.notes

This is a python program. Therefore, it is necessary to have python installed.

There are some additional packages needed, such as PyOpenGL and PIL (Python Imaging Library):

  1. sudo dnf install python2-pyopengl python2-pillow
  1. sudo dnf install python3-pyopengl python3-pillow
  1. sudo apt-get install python-opengl python-pil
  1. sudo apt-get install python3-opengl python3-pil
  1. sudo port install py27-opengl py27-Pillow
  1. sudo port install py36-opengl py36-Pillow

To run the program:

  1. model_name is the OFF file to be read.
  2. texture_name is the initial image to be used as texture.
  3. -t switches between using the Idle callback function or _timer function.
  4. -v turns on the verbose mode.

It is assumed that:

at the same level from where openPolyhedron.py is executed.

In Python, __debug__ is a constant used to determine if calls to assert should result in code being generated.

See also
https://ironboundsoftware.com/blog/2017/01/09/python-__debug__/
https://stackoverflow.com/questions/1693088/what-is-the-use-of-pythons-basic-optimizations-mode-python-o

The OFF format is basically PLY without the header:

  1. the first line contains the word OFF,
  2. the second line is optional, and tells whether vertex indices start at 0 or 1,
  3. and the third line, indicates the number of vertices and faces (polygons).
  4. OFF example for a cube:
 
        OFF
        0
        8 6
        1.0  1.0  1.0
        -1.0  1.0  1.0
        -1.0 -1.0  1.0
        1.0 -1.0  1.0
        1.0  1.0 -1.0
        -1.0  1.0 -1.0
        -1.0 -1.0 -1.0
        1.0 -1.0 -1.0
        4 5 1 0 4
        4 4 7 6 5
        4 4 0 3 7
        4 2 6 7 3
        4 0 1 2 3
        4 1 5 6 2
 
 
Todo:

[graphical interface, read PLY directly]

Qt4 or Qt5 based

PLY reader, writer

Screen Shots

dodecahedron.png
Dodecahedron
dodec-open.png
Flattened
texture-dodec.png
Projected
dodec-velazques.png
Textured
dolphin1.png
Dolphin
dolphin-open.png
Flattened
dolphin-flat.png
Projected
dolphin.png
Textured

Dodecahedron

Unfolded

Projected

Textured

Dolphin

Flattened

Projected

Textured