Skip to content

Commit d3fcc9d

Browse files
jacobrkerstetterRobPasMuepyansys-ci-botpre-commit-ci[bot]
authored
feat: revolve faces and revolve faces by helix options (#1842)
Co-authored-by: Roberto Pastor Muela <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Jacob Kerstetter <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3835d66 commit d3fcc9d

File tree

4 files changed

+166
-2
lines changed

4 files changed

+166
-2
lines changed

doc/changelog.d/1842.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
revolve faces and revolve faces by helix options

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
]
2525

2626
dependencies = [
27-
"ansys-api-geometry==0.4.49",
27+
"ansys-api-geometry==0.4.50",
2828
"ansys-tools-path>=0.3,<1",
2929
"attrs!=24.3.0",
3030
"beartype>=0.11.0,<0.20",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ def revolve_faces(
922922
selection: Union["Face", list["Face"]],
923923
axis: Line,
924924
angle: Real,
925+
extrude_type: ExtrudeType = ExtrudeType.ADD,
925926
) -> list["Body"]:
926927
"""Revolve face around an axis.
927928
@@ -933,6 +934,8 @@ def revolve_faces(
933934
Axis of revolution.
934935
angle : Real
935936
Angular distance to revolve.
937+
extrude_type : ExtrudeType, default: ExtrudeType.ADD
938+
Type of extrusion to be performed.
936939
937940
Returns
938941
-------
@@ -952,6 +955,7 @@ def revolve_faces(
952955
selection=[object._grpc_id for object in selection],
953956
axis=line_to_grpc_line(axis),
954957
angle=angle,
958+
extrude_type=extrude_type.value,
955959
)
956960
)
957961

@@ -1035,6 +1039,7 @@ def revolve_faces_by_helix(
10351039
taper_angle: Real,
10361040
right_handed: bool,
10371041
both_sides: bool,
1042+
extrude_type: ExtrudeType = ExtrudeType.ADD,
10381043
) -> list["Body"]:
10391044
"""Revolve face around an axis in a helix shape.
10401045
@@ -1056,6 +1061,8 @@ def revolve_faces_by_helix(
10561061
Right-handed helix if ``True``, left-handed if ``False``.
10571062
both_sides : bool,
10581063
Create on both sides if ``True``, one side if ``False``.
1064+
extrude_type : ExtrudeType, default: ExtrudeType.ADD
1065+
Type of extrusion to be performed.
10591066
10601067
Returns
10611068
-------
@@ -1080,6 +1087,7 @@ def revolve_faces_by_helix(
10801087
taper_angle=taper_angle,
10811088
right_handed=right_handed,
10821089
both_sides=both_sides,
1090+
extrude_type=extrude_type.value,
10831091
)
10841092
)
10851093

tests/integration/test_geometry_commands.py

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
OffsetMode,
3232
)
3333
from ansys.geometry.core.math import Plane, Point2D, Point3D, UnitVector3D
34-
from ansys.geometry.core.math.constants import UNITVECTOR3D_Z
34+
from ansys.geometry.core.math.constants import UNITVECTOR3D_Y, UNITVECTOR3D_Z
3535
from ansys.geometry.core.misc import UNITS
3636
from ansys.geometry.core.misc.measurements import Angle, Distance
3737
from ansys.geometry.core.modeler import Modeler
@@ -569,6 +569,59 @@ def test_revolve_faces(modeler: Modeler):
569569
assert len(base.faces) == 5
570570

571571

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(
605+
Point2D([3 * pitch, -3 * pitch], UNITS.mm), Point2D([-2 * pitch, pitch], UNITS.mm)
606+
)
607+
cut_surface = design.create_surface("Cut", sketch2)
608+
609+
assert design.bodies[0].volume.m == pytest.approx(
610+
Quantity(1.16587614e-7, UNITS.m**3).m, rel=1e-6, abs=1e-8
611+
)
612+
613+
modeler.geometry_commands.revolve_faces(
614+
cut_surface.faces,
615+
Line(Point3D([0, 0, 0], UNITS.mm), UNITVECTOR3D_Z),
616+
np.pi * 2,
617+
ExtrudeType.CUT,
618+
)
619+
620+
assert design.bodies[0].volume.m == pytest.approx(
621+
Quantity(1.06173048542e-07, UNITS.m**3).m, rel=1e-6, abs=1e-8
622+
)
623+
624+
572625
def test_revolve_faces_up_to(modeler: Modeler):
573626
"""Test revolve faces up to."""
574627
design = modeler.create_design("revolve_faces_up_to")
@@ -614,6 +667,108 @@ def test_revolve_faces_by_helix(modeler: Modeler):
614667
assert len(base.faces) == 6
615668

616669

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

0 commit comments

Comments
 (0)