The construction of the triangle donut is a series of quads that
bridge from one triangular cross section of the donut to the next
triangle.
Each cross-section can be defined by an angle θ. The way we define
the triangular cross-section can be represented by cylindrical coordinates
- vertex1 = [ r1, θ, 0 ]
- vertex2 = [ r2, θ, z ]
- vertex3 = [ r2, θ, -z ]
converting these to cartesian coordinates we get
- vertex1 = [ r1cos(θ), r1sin(θ), 0 ]
- vertex2 = [ r2cos(θ), r2sin(θ), z ]
- vertex3 = [ r2cos(θ), r2sin(θ), -z ]
The triangle donut is constructed from 2*nChunks rings, so we
use the for i in range(2*nChunks): python loop. Each ring
will have 3 vertices, so the first vertex in ring i will have the index i*3.
In the code we also refer to the indices for the vertices on the next ring that we have not yet created: v4, v5, v6. For a special case: when we are on the final ring we set these indices to refer to the very first ring created (because donuts circle back to their beginning).
In the following code example compare the vertex list of each face
with the diagram below. It is a counterclockwise enumeration from the
outside of the surface (which is necessary if you want the face
normals to point outward).
faces.append( [v1, v4, v5, v2] )
faces.append( [v2, v5, v6, v3] )
faces.append( [v3, v6, v4, v1] )