|
41 | 41 | SurfaceType,
|
42 | 42 | )
|
43 | 43 | from ansys.geometry.core.designer.body import CollisionType, FillStyle, MasterBody
|
| 44 | +from ansys.geometry.core.designer.component import SweepWithGuideData |
44 | 45 | from ansys.geometry.core.designer.face import FaceLoopType
|
45 | 46 | from ansys.geometry.core.designer.part import MasterComponent, Part
|
46 | 47 | from ansys.geometry.core.errors import GeometryExitedError, GeometryRuntimeError
|
|
71 | 72 | Torus,
|
72 | 73 | )
|
73 | 74 | from ansys.geometry.core.shapes.box_uv import BoxUV
|
| 75 | +from ansys.geometry.core.shapes.curves.nurbs import NURBSCurve |
74 | 76 | from ansys.geometry.core.shapes.parameterization import (
|
75 | 77 | Interval,
|
76 | 78 | )
|
@@ -2809,6 +2811,55 @@ def test_sweep_chain(modeler: Modeler):
|
2809 | 2811 | assert body.volume.m == 0
|
2810 | 2812 |
|
2811 | 2813 |
|
| 2814 | +def test_sweep_with_guide(modeler: Modeler): |
| 2815 | + """Test creating a body by sweeping a profile with a guide curve.""" |
| 2816 | + design = modeler.create_design("SweepWithGuide") |
| 2817 | + |
| 2818 | + # Create path points for the sweep path |
| 2819 | + path_points = [ |
| 2820 | + Point3D([0.0, 0.0, 0.15]), |
| 2821 | + Point3D([0.05, 0.0, 0.1]), |
| 2822 | + Point3D([0.1, 0.0, 0.05]), |
| 2823 | + Point3D([0.15, 0.0, 0.1]), |
| 2824 | + Point3D([0.2, 0.0, 0.15]), |
| 2825 | + ] |
| 2826 | + nurbs_path = NURBSCurve.fit_curve_from_points(path_points, degree=3) |
| 2827 | + n_l_points = len(path_points) |
| 2828 | + path_interval = Interval(1.0 / (n_l_points - 1), (n_l_points - 2.0) / (n_l_points - 1)) |
| 2829 | + trimmed_path = nurbs_path.trim(path_interval) |
| 2830 | + |
| 2831 | + # Create a simple circular profile sketch |
| 2832 | + profile_plane = Plane(origin=path_points[1]) |
| 2833 | + profile_sketch = Sketch(profile_plane) |
| 2834 | + profile_sketch.circle(Point2D([0, 0]), 0.01) # 0.01 radius |
| 2835 | + |
| 2836 | + # Create guide curve points (offset from path) |
| 2837 | + guide_points = [Point3D([p.x.m, p.y.m + 0.01, p.z.m]) for p in path_points] |
| 2838 | + guide_curve = NURBSCurve.fit_curve_from_points(guide_points, degree=3) |
| 2839 | + guide_interval = Interval(1.0 / (n_l_points - 1), (n_l_points - 2.0) / (n_l_points - 1)) |
| 2840 | + trimmed_guide = guide_curve.trim(guide_interval) |
| 2841 | + |
| 2842 | + # Sweep the profile along the path with the guide curve |
| 2843 | + sweep_data = [ |
| 2844 | + SweepWithGuideData( |
| 2845 | + name="SweptBody", |
| 2846 | + parent_id=design.id, |
| 2847 | + sketch=profile_sketch, |
| 2848 | + path=trimmed_path, |
| 2849 | + guide=trimmed_guide, |
| 2850 | + tight_tolerance=True, |
| 2851 | + ) |
| 2852 | + ] |
| 2853 | + sweep_body = design.sweep_with_guide(sweep_data=sweep_data)[0] |
| 2854 | + |
| 2855 | + assert sweep_body is not None |
| 2856 | + assert sweep_body.name == "SweptBody" |
| 2857 | + assert sweep_body.is_surface |
| 2858 | + assert len(sweep_body.faces) == 1 |
| 2859 | + assert len(sweep_body.edges) == 2 |
| 2860 | + assert len(sweep_body.vertices) == 0 |
| 2861 | + |
| 2862 | + |
2812 | 2863 | def test_create_body_from_loft_profile(modeler: Modeler):
|
2813 | 2864 | """Test the ``create_body_from_loft_profile()`` method to create a vase
|
2814 | 2865 | shape.
|
|
0 commit comments