# Geodesic Dome Reference Geometry

Tessellates a sphere into triangles and generates a reference point at each vertex.  Demonstrates how complex reference geometry can be created.

To increase the number of triangles increase the detail value, however use with caution as a small increase can result in a very large number of triangles which will take a long time to generate.

```# tessellates a sphere into triangles and generates a reference point at each vertex
# http://musingsofninjarat.wordpress.com/spheres-through-triangle-tessellation/

from math import *

A = 0.525731112119133606
B = 0.850650808352039932

icosa_indices = [0 for x in xrange(20)]
icosa_indices  = [0,4,1]
icosa_indices  = [0,9,4]
icosa_indices  = [9,5,4]
icosa_indices  = [4,5,8]
icosa_indices  = [4,8,1]
icosa_indices  = [8,10,1]
icosa_indices  = [8,3,10]
icosa_indices  = [5,3,8]
icosa_indices  = [5,2,3]
icosa_indices  = [2,7,3]
icosa_indices = [7,10,3]
icosa_indices = [7,6,10]
icosa_indices = [7,11,6]
icosa_indices = [11,0,6]
icosa_indices = [0,1,6]
icosa_indices = [6,1,10]
icosa_indices = [9,0,11]
icosa_indices = [9,11,2]
icosa_indices = [9,2,5]
icosa_indices = [7,2,11]

icosa_verts = [0 for x in xrange(12)]
icosa_verts  = [A,0.0,-B]
icosa_verts  = [-A,0.0,-B]
icosa_verts  = [A,0.0,B]
icosa_verts  = [-A,0.0,B]
icosa_verts  = [0.0,-B,-A]
icosa_verts  = [0.0,-B,A]
icosa_verts  = [0.0,B,-A]
icosa_verts  = [0.0,B,A]
icosa_verts  = [-B,-A,0.0]
icosa_verts  = [B,-A,0.0]
icosa_verts = [-B,A,0.0]
icosa_verts = [B,A,0.0]

def normalize_vert(a):
d = sqrt(a*a + a*a + a*a)
a = a / d
a = a / d
a = a / d
return a

def draw_recursive_tri(a, b, c, div, r, vertices):
if div == 0:
v1 = (a*r, a*r, a*r)
v2 = (b*r, b*r, b*r)
v3 = (c*r, c*r, c*r)
else:
ab = [0, 0, 0]
ac = [0, 0, 0]
bc = [0, 0, 0]

for i in range(0, 3):
ab[i] = (a[i] + b[i]) / 2.0
ac[i] = (a[i] + c[i]) / 2.0
bc[i] = (b[i] + c[i]) / 2.0

ab = normalize_vert(ab)
ac = normalize_vert(ac)
bc = normalize_vert(bc)

draw_recursive_tri(a, ab, ac, div - 1, r, vertices)
draw_recursive_tri(b, bc, ab, div - 1, r, vertices)
draw_recursive_tri(c, ac, bc, div - 1, r, vertices)
draw_recursive_tri(ab, bc, ac, div - 1, r, vertices)

# calculates the triangle vertices for a given sphere and level of detail
# we use a set because each vertex must be unique and sets can only contain unique values
vertices = set()
for i in range(0, 20):
draw_recursive_tri(icosa_verts[icosa_indices[i]], icosa_verts[icosa_indices[i]], icosa_verts[icosa_indices[i]], detail, radius, vertices);
return vertices

# use a low level of detail - increasing this value drastically increases the number of triangles
# warning - must be zero or a positive integer
Detail = 1
# radius of sphere in millimeters

# generate a set of triangle vertices

# create a new part
MyPart = Part('Geodesic Sphere')
# add the reference points to the part
Number = 0
for Vertex in Vertices:
MyPart.AddPoint('Geodesic ' + str(Number), Vertex, Vertex, Vertex)
Number = Number + 1```

Did you find it helpful? Yes No

Send feedback 