3131 OffsetMode ,
3232)
3333from ansys .geometry .core .math import Plane , Point2D , Point3D , UnitVector3D
34+ from ansys .geometry .core .math .constants import UNITVECTOR3D_Y , UNITVECTOR3D_Z
3435from ansys .geometry .core .misc import UNITS
36+ from ansys .geometry .core .misc .measurements import Angle , Distance
3537from ansys .geometry .core .modeler import Modeler
3638from ansys .geometry .core .shapes .curves .line import Line
3739from 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+
570623def 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+
615766def 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
640792def test_split_body_by_plane (modeler : Modeler ):
0 commit comments