Skip to content

Commit 831dcf1

Browse files
added ExrtudeType to revolve_faces and revolve_faces_with_helix
added tests for both methods
1 parent d0904ff commit 831dcf1

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ def revolve_faces(
861861
selection: Union["Face", list["Face"]],
862862
axis: Line,
863863
angle: Real,
864+
extrude_type: ExtrudeType = ExtrudeType.ADD,
864865
) -> list["Body"]:
865866
"""Revolve face around an axis.
866867
@@ -872,6 +873,8 @@ def revolve_faces(
872873
Axis of revolution.
873874
angle : Real
874875
Angular distance to revolve.
876+
extrude_type : ExtrudeType, default: ExtrudeType.ADD
877+
Type of extrusion to be performed.
875878
876879
Returns
877880
-------
@@ -891,6 +894,7 @@ def revolve_faces(
891894
selection=[object._grpc_id for object in selection],
892895
axis=line_to_grpc_line(axis),
893896
angle=angle,
897+
extrude_type=extrude_type.value,
894898
)
895899
)
896900

@@ -974,6 +978,7 @@ def revolve_faces_by_helix(
974978
taper_angle: Real,
975979
right_handed: bool,
976980
both_sides: bool,
981+
extrude_type: ExtrudeType = ExtrudeType.ADD,
977982
) -> list["Body"]:
978983
"""Revolve face around an axis in a helix shape.
979984
@@ -995,6 +1000,8 @@ def revolve_faces_by_helix(
9951000
Right-handed helix if ``True``, left-handed if ``False``.
9961001
both_sides : bool,
9971002
Create on both sides if ``True``, one side if ``False``.
1003+
extrude_type : ExtrudeType, default: ExtrudeType.ADD
1004+
Type of extrusion to be performed.
9981005
9991006
Returns
10001007
-------
@@ -1019,6 +1026,7 @@ def revolve_faces_by_helix(
10191026
taper_angle=taper_angle,
10201027
right_handed=right_handed,
10211028
both_sides=both_sides,
1029+
extrude_type=extrude_type.value,
10221030
)
10231031
)
10241032

tests/integration/test_geometry_commands.py

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
OffsetMode,
3232
)
3333
from ansys.geometry.core.math import Plane, Point2D, Point3D, UnitVector3D
34+
from ansys.geometry.core.math.constants import UNITVECTOR3D_Y, UNITVECTOR3D_Z
3435
from ansys.geometry.core.misc import UNITS
36+
from ansys.geometry.core.misc.measurements import Angle, Distance
3537
from ansys.geometry.core.modeler import Modeler
3638
from ansys.geometry.core.shapes.curves.line import Line
3739
from ansys.geometry.core.sketch.sketch import Sketch
@@ -567,6 +569,57 @@ def test_revolve_faces(modeler: Modeler):
567569
assert len(base.faces) == 5
568570

569571

572+
def test_revolve_faces_with_options(modeler: Modeler):
573+
# Parameters
574+
pitch = 0.7
575+
inner_diameter = 4
576+
width = 7
577+
height = 3.2
578+
579+
# Cylinder Creation
580+
design = modeler.create_design("SquareNut")
581+
sketch = Sketch()
582+
sketch.circle(Point2D([0, 0], UNITS.mm), Quantity(inner_diameter/2, UNITS.mm))
583+
cylinder0 = design.extrude_sketch("SquareNut", sketch, Quantity(height, UNITS.mm))
584+
585+
# Create HexNut
586+
sketch1 = Sketch()
587+
sketch1.polygon(Point2D([0,0]), Distance(width/2,UNITS.mm), 4, Angle(45))
588+
hex_nut = design.extrude_sketch("HexNut", sketch1, Quantity(height, UNITS.mm), "+", False)
589+
590+
copy1 = cylinder0.copy(design, "SquareNut")
591+
copy2 = hex_nut.copy(design, "SquareNut")
592+
copy2.subtract(copy1, False)
593+
design.delete_body(design.bodies[0].id)
594+
design.delete_body(design.bodies[0].id)
595+
596+
plane2 = Plane(
597+
Point3D([0, (width)/2, height], UNITS.mm),
598+
direction_x = UnitVector3D([0, 1, 0]),
599+
direction_y = UnitVector3D([0, 0, 1])
600+
)
601+
sketch2 = Sketch(plane2)
602+
sketch2.segment(Point2D([-2*pitch, pitch], UNITS.mm), Point2D([3*pitch, 0], UNITS.mm))
603+
sketch2.segment(Point2D([3*pitch, 0], UNITS.mm), Point2D([3*pitch, -3*pitch], UNITS.mm))
604+
sketch2.segment(Point2D([3*pitch, -3*pitch], UNITS.mm), Point2D([-2*pitch, pitch], UNITS.mm))
605+
cut_surface = design.create_surface('Cut', sketch2)
606+
607+
assert design.bodies[0].volume.m == pytest.approx(
608+
Quantity(1.16587614e-7, UNITS.m**3).m, rel=1e-6, abs=1e-8
609+
)
610+
611+
modeler.geometry_commands.revolve_faces(
612+
cut_surface.faces,
613+
Line(Point3D([0, 0, 0], UNITS.mm), UNITVECTOR3D_Z),
614+
np.pi*2,
615+
ExtrudeType.CUT
616+
)
617+
618+
assert design.bodies[0].volume.m == pytest.approx(
619+
Quantity(1.06173048542e-07, UNITS.m**3).m, rel=1e-6, abs=1e-8
620+
)
621+
622+
570623
def test_revolve_faces_up_to(modeler: Modeler):
571624
"""Test revolve faces up to."""
572625
design = modeler.create_design("revolve_faces_up_to")
@@ -612,6 +665,104 @@ def test_revolve_faces_by_helix(modeler: Modeler):
612665
assert len(base.faces) == 6
613666

614667

668+
def test_revolve_faces_by_helix_with_options(modeler: Modeler):
669+
# Parameters
670+
pitch = 0.7
671+
inner_diameter = 4
672+
width = 7
673+
height = 3.2
674+
675+
thread_length = height - pitch/2
676+
677+
# Cylinder Creation
678+
design = modeler.create_design("SquareNut")
679+
sketch = Sketch()
680+
sketch.circle(Point2D([0, 0], UNITS.mm), Quantity(inner_diameter/2, UNITS.mm))
681+
cylinder0 = design.extrude_sketch("SquareNut", sketch, Quantity(height, UNITS.mm))
682+
683+
# Create HexNut
684+
sketch1 = Sketch()
685+
sketch1.polygon(Point2D([0,0]), Distance(width/2,UNITS.mm), 4, Angle(45))
686+
hex_nut = design.extrude_sketch("HexNut", sketch1, Quantity(height, UNITS.mm), "+", False)
687+
688+
copy1 = cylinder0.copy(design, "SquareNut")
689+
copy2 = hex_nut.copy(design, "SquareNut")
690+
copy2.subtract(copy1, False)
691+
design.delete_body(design.bodies[0].id)
692+
design.delete_body(design.bodies[0].id)
693+
694+
plane2 = Plane(
695+
Point3D([0, (width)/2, height], UNITS.mm),
696+
direction_x = UnitVector3D([0, 1, 0]),
697+
direction_y = UnitVector3D([0, 0, 1])
698+
)
699+
sketch2 = Sketch(plane2)
700+
sketch2.segment(Point2D([-2*pitch,pitch], UNITS.mm), Point2D([3*pitch, 0], UNITS.mm))
701+
sketch2.segment(Point2D([3*pitch, 0], UNITS.mm), Point2D([3*pitch, -3*pitch], UNITS.mm))
702+
sketch2.segment(Point2D([3*pitch, -3*pitch], UNITS.mm), Point2D([-2*pitch,pitch], UNITS.mm))
703+
cut_surface = design.create_surface('Cut', sketch2)
704+
705+
assert design.bodies[0].volume.m == pytest.approx(
706+
Quantity(1.16587614e-7, UNITS.m**3).m, rel=1e-6, abs=1e-8
707+
)
708+
709+
modeler.geometry_commands.revolve_faces(
710+
cut_surface.faces,
711+
Line(Point3D([0, 0, 0], UNITS.mm), UNITVECTOR3D_Z),
712+
np.pi*2,
713+
ExtrudeType.CUT
714+
)
715+
assert design.bodies[0].volume.m == pytest.approx(
716+
Quantity(1.06173048542e-07, UNITS.m**3).m, rel=1e-6, abs=1e-8
717+
)
718+
719+
starting_face_count = len(design.bodies[0].faces)
720+
current_face_count = len(design.bodies[0].faces)
721+
x = 0
722+
while starting_face_count == current_face_count:
723+
if x > 1000:
724+
break
725+
modeler.geometry_commands.extrude_faces(design.bodies[0].faces[-1], (0.05)/1000)
726+
current_face_count = len(design.bodies[0].faces)
727+
x += 1
728+
729+
thread_height = pitch * ((3**0.5/2))
730+
thread_plane = Plane(
731+
Point3D([0, (inner_diameter)/2, 0], UNITS.mm),
732+
direction_x=UNITVECTOR3D_Y,
733+
direction_y=UNITVECTOR3D_Z
734+
)
735+
thread_sketch = Sketch(thread_plane)
736+
thread_sketch.segment(Point2D([0,0], UNITS.mm), Point2D([0, pitch/2], UNITS.mm))
737+
thread_sketch.segment(
738+
Point2D([0, pitch/2], UNITS.mm), Point2D([thread_height*(3/8), (pitch/2-pitch/8)], UNITS.mm)
739+
)
740+
thread_sketch.segment(
741+
Point2D([thread_height*(3/8), (pitch/2-pitch/8)], UNITS.mm),
742+
Point2D([thread_height*(3/8), ((pitch/4)/2)], UNITS.mm)
743+
)
744+
thread_sketch.segment(
745+
Point2D([0,0], UNITS.mm), Point2D([thread_height*(3/8), ((pitch/4)/2)], UNITS.mm)
746+
)
747+
thread_surface = design.create_surface('Thread', thread_sketch)
748+
dir = UNITVECTOR3D_Z
749+
axs = UNITVECTOR3D_Z
750+
modeler.geometry_commands.revolve_faces_by_helix(
751+
thread_surface.faces[0],
752+
Line(Point3D([0, 0, 0], UNITS.mm), axs),
753+
dir,
754+
2*thread_length/1000,
755+
pitch/1000,0,
756+
True,
757+
True,
758+
ExtrudeType.CUT
759+
)
760+
761+
assert design.bodies[0].volume.m == pytest.approx(
762+
Quantity(1.06173048542e-07, UNITS.m**3).m, rel=1e-6, abs=1e-8
763+
)
764+
765+
615766
def test_replace_face(modeler: Modeler):
616767
"""Test replacing a face with another face."""
617768
design = modeler.create_design("replace_face")
@@ -635,6 +786,7 @@ def test_replace_face(modeler: Modeler):
635786
Quantity(0.992146018366, UNITS.m**3).m, rel=1e-6, abs=1e-8
636787
)
637788
assert len(base.faces) == 7
789+
638790

639791

640792
def test_split_body_by_plane(modeler: Modeler):

0 commit comments

Comments
 (0)