|
31 | 31 | OffsetMode, |
32 | 32 | ) |
33 | 33 | 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 |
35 | 35 | from ansys.geometry.core.misc import UNITS |
36 | 36 | from ansys.geometry.core.misc.measurements import Angle, Distance |
37 | 37 | from ansys.geometry.core.modeler import Modeler |
@@ -569,6 +569,59 @@ def test_revolve_faces(modeler: Modeler): |
569 | 569 | assert len(base.faces) == 5 |
570 | 570 |
|
571 | 571 |
|
| 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 | + |
572 | 625 | def test_revolve_faces_up_to(modeler: Modeler): |
573 | 626 | """Test revolve faces up to.""" |
574 | 627 | design = modeler.create_design("revolve_faces_up_to") |
@@ -614,6 +667,108 @@ def test_revolve_faces_by_helix(modeler: Modeler): |
614 | 667 | assert len(base.faces) == 6 |
615 | 668 |
|
616 | 669 |
|
| 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 | + |
617 | 772 | def test_replace_face(modeler: Modeler): |
618 | 773 | """Test replacing a face with another face.""" |
619 | 774 | design = modeler.create_design("replace_face") |
|
0 commit comments