Since the question is now the main result of a Google search (math cheating - No. 2), I thought that I could also add code.
The full console program is given below and should compile and run and be generally self-evident.
The algorithm is based on Wikipedia article (thanks, mt_ from math.stackoverflow.com )
This code should print the correct list of vertices for you. Your problem is mainly related to the Program.MakeDodecahedron
method, however don't just copy and paste it because you need to change this to use your own vertex data structure instead of my mock Vertex
object. You can easily use XNA Vector3 , which has a constructor with the same signature as my Vertex
. Also because my Vertex.ToString
method Vertex.ToString
hacked, this program can print an ugly output table when used with Vector3
, so keep that in mind.
Also note that this is a demo (n imprefect). For example, if you create many tetrahedra, you will uselessly re-read constants (for example, the golden ratio) for each call.
With XNA, especially if you use Microsoft.Xna.Framework
, you can also easily make your dodecahedron in 3D. You can adapt the code with this tutorial for this purpose.
using System; using System.Collections.Generic; namespace DodecahedronVertices { class Program { static void Main() {
Since my code is probably quite verbose and widespread, I would recommend reading it in that it supports folding for-loops and other code structures.
source share