Browsed by
Tag: reference

Geodesic Dome Reference Geometry

Geodesic Dome Reference Geometry

Compatible with WizoScript versions: 1.42

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
# adapted from
# 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]  = [0,4,1]
icosa_indices[1]  = [0,9,4]
icosa_indices[2]  = [9,5,4]
icosa_indices[3]  = [4,5,8]
icosa_indices[4]  = [4,8,1]
icosa_indices[5]  = [8,10,1]
icosa_indices[6]  = [8,3,10]
icosa_indices[7]  = [5,3,8]
icosa_indices[8]  = [5,2,3]
icosa_indices[9]  = [2,7,3]
icosa_indices[10] = [7,10,3]
icosa_indices[11] = [7,6,10]
icosa_indices[12] = [7,11,6]
icosa_indices[13] = [11,0,6]
icosa_indices[14] = [0,1,6]
icosa_indices[15] = [6,1,10]
icosa_indices[16] = [9,0,11]
icosa_indices[17] = [9,11,2]
icosa_indices[18] = [9,2,5]
icosa_indices[19] = [7,2,11]
 
icosa_verts = [0 for x in xrange(12)]
icosa_verts[0]  = [A,0.0,-B]
icosa_verts[1]  = [-A,0.0,-B]
icosa_verts[2]  = [A,0.0,B]
icosa_verts[3]  = [-A,0.0,B]
icosa_verts[4]  = [0.0,-B,-A]
icosa_verts[5]  = [0.0,-B,A]
icosa_verts[6]  = [0.0,B,-A]
icosa_verts[7]  = [0.0,B,A]
icosa_verts[8]  = [-B,-A,0.0]
icosa_verts[9]  = [B,-A,0.0]
icosa_verts[10] = [-B,A,0.0]
icosa_verts[11] = [B,A,0.0]
 
def normalize_vert(a):
  d = sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2])
  a[0] = a[0] / d
  a[1] = a[1] / d
  a[2] = a[2] / d
  return a
   
def draw_recursive_tri(a, b, c, div, r, vertices):
  if div == 0:
    v1 = (a[0]*r, a[1]*r, a[2]*r)
    v2 = (b[0]*r, b[1]*r, b[2]*r)
    v3 = (c[0]*r, c[1]*r, c[2]*r)
    vertices.add(v1)
    vertices.add(v2)
    vertices.add(v3)
  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
def calculate_sphere(detail, radius):
  # 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][0]], icosa_verts[icosa_indices[i][1]], icosa_verts[icosa_indices[i][2]], detail, radius, vertices);
  return vertices
 
# use a low level of detail - increasing this value drastically increases the number of triangles
Detail = 1
# radius of sphere in millimeters
Radius = 10
 
# generate a set of triangle vertices
Vertices = calculate_sphere(Detail, Radius)
 
# 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[0], Vertex[1], Vertex[2])
  Number = Number + 1
Reference Geometry

Reference Geometry

Compatible with WizoScript versions: 1.40

A short example showing how to create reference planes, axes and points.

# demonstrates creating reference geometry
 
# create a new part and get the xy plane
MyPart = Part("My Part")
XYPlane = MyPart.GetPlane("XY-Plane")
 
# create planes 100mm above and below the xy plane
TopPlane = MyPart.AddPlane("Top Plane", XYPlane, 100.0)
BottomPlane = MyPart.AddPlane("Bottom Plane", XYPlane, -100.0)
 
# add reference points to bottom plane
Ref1 = MyPart.AddPoint("Ref 1", 50.0, 50.0, -100.0)
Ref2 = MyPart.AddPoint("Ref 2", 50.0, -50.0, -100.0)
Ref3 = MyPart.AddPoint("Ref 3", -50.0, -50.0, -100.0)
Ref4 = MyPart.AddPoint("Ref 4", -50.0, 50.0, -100.0)
 
# add reference axes from points on bottom plane to center of top plane
Axis1 = MyPart.AddAxis("Axis 1", [50.0, 50.0, -100.0], [0.0, 0.0, 100.0])
Axis2 = MyPart.AddAxis("Axis 2", [50.0, -50.0, -100.0], [0.0, 0.0, 100.0])
Axis3 = MyPart.AddAxis("Axis 3", [-50.0, -50.0, -100.0], [0.0, 0.0, 100.0])
Axis4 = MyPart.AddAxis("Axis 4", [-50.0, 50.0, -100.0], [0.0, 0.0, 100.0])