Browsed by
Tag: plane

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)
Cylinder to a Specific Point

Cylinder to a Specific Point

Compatible with WizoScript versions: 1.50

Creates a cylinder that stretches from the origin to a user-defined point. It does this by calculating the plane to start the cylinder from. Demonstrates calculating the equation of a plane then create the plane in Geomagic Design.

# create a cylinder from the origin to an arbitrary point
 
from math import sqrt
 
# ends of cylinder are centered on these points
# first point must be the origin
cyl_p1 = [0, 0, 0]
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]]
 
# get equation of plane
# Ax + By + Cz = D
A = normal_vector[0]
B = normal_vector[1]
C = normal_vector[2]
D = -((A * cyl_p1[0]) + (B * cyl_p1[1]) + (C * cyl_p1[2]))
 
# calculate a point on the plane
plane_p2 = [cyl_p1[0] - 1, cyl_p1[1] - 2, 0]
plane_p2[2] = (0 - D - (A * plane_p2[0]) - (B * plane_p2[1])) / float(C)
 
# calculate another point on the plane
plane_p3 = [cyl_p1[0] - 2, cyl_p1[1] - 2, 0]
plane_p3[2] = (0 - D - (A * plane_p3[0]) - (B * plane_p3[1])) / float(C)
 
# create part
P = Part("Cylinder Test")
 
# create plane using origin and two points on plane
cyl_plane = P.AddPlane("Cyl Plane", cyl_p1, plane_p2, plane_p3)
 
# create circle on plane
sketch = P.AddSketch("Cyl End", cyl_plane)
sketch.AddCircle(cyl_p1[0], cyl_p1[1], diameter, False)
 
# extrude to cylinder
P.AddExtrudeBoss("Cynlinder", sketch, length, True)
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])