Browsed by
Tag: geometry

Polygon Incircle

Polygon Incircle

Compatible with WizoScript versions: 2.51

Polygons in Geomagic Design can be defined by an “exterior” or “interior” circle. The interior circle is typically used for bolt heads. The circle is called an “incircle”. This script shows how to draw a polygon by defining the incircle diameter.

import math
 
# diameter of circle that fits inside polygon
Diameter = 100
# number of sides
Sides = 6
 
# calculate exterior diameter of polygon
EDia = Diameter / math.cos(math.pi / Sides)
 
# create part, create polygon sketch, extrude
P = Part("Hex")
S = P.AddSketch("Hexagon", P.GetPlane("XY-Plane"))
S.AddPolygon(0, 0, EDia, Sides, False)
P.AddExtrudeBoss("Hex Head", S, 10, False)
Creating a Cylinder Between Two Points

Creating a Cylinder Between Two Points

Compatible with WizoScript versions: 1.85

Shows how to create a plane with a specific normal and project 3D points to 2D sketches.

# creates a cylinder between two arbitrary points
 
from math import sqrt
 
# ends of cylinder are centered on these points
cyl_p1 = [1, 5, 2]
cyl_p2 = [10, 14, 8]
 
# diameter of cylinder
diameter = 6
 
# get length of cynlinder using euclidean distance
length = sqrt((cyl_p2[0] - cyl_p1[0])**2 + (cyl_p2[1] - cyl_p1[1])**2 + (cyl_p2[2] - cyl_p1[2])**2)
 
# calculate normal vector for the plane at the first end of the cylinder
normal_vector = [cyl_p2[0] - cyl_p1[0], cyl_p2[1] - cyl_p1[1], cyl_p2[2] - cyl_p1[2]]
 
# create part
P = Part("Cylinder")
 
# create plane for one end of the cylinder
cyl_plane = P.AddPlane("Cyl Start Plane", normal_vector, cyl_p1)
 
P.AddAxis("Cylinder Axis", cyl_p1, cyl_p2)
 
# draw a circle on the plane
S = P.AddSketch("Cylinder End", cyl_plane)
[cx, cy] = S.GlobaltoPoint(cyl_p1[0], cyl_p1[1], cyl_p1[2])
S.AddCircle(cx, cy, diameter, False)
 
# extrude into a cylinder
P.AddExtrudeBoss("Cylinder", S, length, True)
Parameterized Mobius Strip

Parameterized Mobius Strip

Compatible with WizoScript versions: 1.70

Demonstrates generation of a mobius strip based on a set of parameters. Uses 2D sketch copying and rotation followed by a loft. Requires Geomagic Design 16.0.1.16490 or later.

# creates a mobius strip with a configurable number of rotations
 
Mobius = Part("Mobius")
 
# dimensions of mobius strip
Diameter = 100.0
Width = 20.0
Height = 5.0
# number of 360 degree twists in mobius strip
Rotations = 2
# more steps = better accuracy
Steps = 30
 
# calculate how far we rotate through 360 degrees for each step
RotationPerStep = Rotations / float(Steps) * 360.0
DegreesPerStep = 360.0 / Steps
 
# create the base sketch we will use as a template for all other sketches
S0Plane = Mobius.GetPlane("XY-Plane")
S0 = Mobius.AddSketch("S0", S0Plane)
S0.AddRectangle(Diameter, -Height / 2, Diameter + Width, Height / 2, False)
Sketches = [S0]
 
# generate sketches
for Step in range (1, Steps):
  Plane = Mobius.AddPlane("S" + str(Step), S0Plane, Mobius.GetAxis("Y-Axis"), DegreesPerStep * Step)
  Sketch = Mobius.AddSketch("S" + str(Step), Plane)
  Sketch.CopyFrom(S0, RotationPerStep * Step, Diameter + (Width / 2), 0, 0, 0, 0, 0, 100.0)
  Sketches.append(Sketch)
 
# create loft, connecting ends
Mobius.AddLoftBoss("Strip", Sketches, True, True, False, True)
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])