Created
April 5, 2022 11:40
-
-
Save blakseth2/8fafbb5125564335970bb09056921265 to your computer and use it in GitHub Desktop.
Cutting an OCCGeometry Spiral
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=============================== | |
# Cutting a spiral (NOT WORKING) | |
import netgen.occ as occ | |
from netgen.webgui import Draw as GeoDraw | |
import numpy as np | |
tube_axes = occ.Axes(occ.Pnt(0,0,0), occ.Z) | |
tube_radius = 10 | |
spiral_spacing = 2.1 | |
spiral_width = 5 | |
spiral_thickness = 0.8 | |
revs = 3 | |
angle = revs*2*np.pi | |
L = revs*(spiral_thickness + spiral_spacing) + spiral_thickness | |
cyl1 = occ.Cylinder(tube_axes, tube_radius, L).faces[0] | |
cyl2 = occ.Cylinder(tube_axes, tube_radius + spiral_width, L).faces[0] | |
seg1 = occ.Segment(occ.Pnt(0, 0), occ.Pnt(angle, L-spiral_thickness)) | |
seg2 = occ.Segment(occ.Pnt(angle, L-spiral_thickness), occ.Pnt(angle, L)) | |
seg3 = occ.Segment(occ.Pnt(angle, L), occ.Pnt(0, spiral_thickness)) | |
seg4 = occ.Segment(occ.Pnt(0, spiral_thickness), occ.Pnt(0, 0)) | |
arc1 = occ.Edge(seg1, cyl1) | |
arc2 = occ.Edge(seg2, cyl1) | |
arc3 = occ.Edge(seg3, cyl1) | |
arc4 = occ.Edge(seg4, cyl1) | |
arc5 = occ.Edge(seg1, cyl2) | |
arc6 = occ.Edge(seg2, cyl2) | |
arc7 = occ.Edge(seg3, cyl2) | |
arc8 = occ.Edge(seg4, cyl2) | |
wire1 = occ.Wire([arc1, arc2, arc3, arc4]) | |
wire2 = occ.Wire([arc5, arc6, arc7, arc8]) | |
spiral = occ.ThruSections([wire1, wire2]) | |
cut = occ.Box(occ.Pnt(tube_radius + 0.5*spiral_width, 1, 0), occ.Pnt(tube_radius + 1.5*spiral_width, 2, L)) | |
cut_spiral = spiral - cut | |
GeoDraw(cut_spiral) # Produces blank output screen. | |
GeoDraw(occ.Compound([cut, spiral])) # Confirms that cut and cut_spiral have a non-zero intersection. | |
#=============================== | |
# Cutting a cylinder (working) | |
tube_axes = occ.Axes(occ.Pnt(0,0,0), occ.Z) | |
cyl1 = occ.Cylinder(tube_axes, 1, 1).faces[0] | |
seg1 = occ.Segment(occ.Pnt(0, 0), occ.Pnt(2*np.pi, 0)) | |
seg2 = occ.Segment(occ.Pnt(0, 1), occ.Pnt(2*np.pi, 1)) | |
arc1 = occ.Edge(seg1, cyl1) | |
arc2 = occ.Edge(seg2, cyl1) | |
wire1 = occ.Wire([arc1]) | |
wire2 = occ.Wire([arc2]) | |
cylinder = occ.ThruSections([wire1, wire2]) | |
cut = occ.Box(occ.Pnt(0,0,0), occ.Pnt(2,2,2)) | |
cut_cylinder = cylinder - cut | |
GeoDraw(cut_cylinder) # Visualizes 3/4 of a cylinder, as expected. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment