|
40 | 40 | SurfaceType, |
41 | 41 | ) |
42 | 42 | from ansys.geometry.core.designer.body import CollisionType, FillStyle, MasterBody |
| 43 | +from ansys.geometry.core.designer.component import SweepWithGuideData |
43 | 44 | from ansys.geometry.core.designer.face import FaceLoopType |
44 | 45 | from ansys.geometry.core.designer.part import MasterComponent, Part |
45 | 46 | from ansys.geometry.core.errors import GeometryExitedError, GeometryRuntimeError |
|
56 | 57 | UnitVector3D, |
57 | 58 | Vector3D, |
58 | 59 | ) |
| 60 | +from ansys.geometry.core.math.matrix import Matrix44 |
59 | 61 | from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Accuracy, Angle, Distance, checks |
60 | 62 | from ansys.geometry.core.misc.auxiliary import DEFAULT_COLOR |
61 | 63 | from ansys.geometry.core.parameters.parameter import ParameterType, ParameterUpdateStatus |
@@ -2813,90 +2815,49 @@ def test_sweep_with_guide(modeler: Modeler): |
2813 | 2815 | """Test creating a body by sweeping a profile with a guide curve.""" |
2814 | 2816 | design = modeler.create_design("SweepWithGuide") |
2815 | 2817 |
|
2816 | | - # Set up path points array |
2817 | | - path_points = [] |
2818 | | - path_points.append(Point3D([0.0, 0.0, 0.15])) |
2819 | | - path_points.append(Point3D([0.05, 0.0, 0.1])) |
2820 | | - path_points.append(Point3D([0.1, 0.0, 0.05])) |
2821 | | - path_points.append(Point3D([0.15, 0.0, 0.1])) |
2822 | | - path_points.append(Point3D([0.2, 0.0, 0.15])) |
2823 | | - |
2824 | | - npoints = len(path_points) |
2825 | | - for i in range(2): |
2826 | | - for j in range(1, npoints): |
2827 | | - orgp = path_points[j] |
2828 | | - p = Point3D([orgp[0] + (i + 1) * path_points[npoints - 1][0], orgp[1], orgp[2]]) |
2829 | | - path_points.append(p) |
2830 | | - |
2831 | | - # Insert values at the beginning and end |
2832 | | - start_point = [ |
2833 | | - Point3D( |
2834 | | - [ |
2835 | | - path_points[npoints - 2][0] - path_points[npoints - 1][0], |
2836 | | - path_points[npoints - 2][1], |
2837 | | - path_points[npoints - 2][2], |
2838 | | - ], |
2839 | | - ) |
| 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]), |
2840 | 2825 | ] |
2841 | | - path_points = start_point + path_points |
2842 | | - end_point = Point3D( |
2843 | | - [ |
2844 | | - path_points[2][0] + (1 + 2) * path_points[npoints][0], |
2845 | | - path_points[2][1], |
2846 | | - path_points[2][2], |
2847 | | - ], |
2848 | | - ) |
2849 | | - path_points.append(end_point) |
2850 | | - |
2851 | | - # Create the NURBS curve through the points |
2852 | | - nurbs_curve = NURBSCurve.fit_curve_from_points(path_points, 3) |
| 2826 | + nurbs_path = NURBSCurve.fit_curve_from_points(path_points, degree=3) |
2853 | 2827 | n_l_points = len(path_points) |
2854 | | - yarn_path = nurbs_curve.trim( |
2855 | | - Interval(1.0 / (n_l_points - 1), (n_l_points - 2.0) / (n_l_points - 1)) |
2856 | | - ) |
2857 | | - |
2858 | | - # Create the lenticular profile sketch |
2859 | | - yarn_path_eval = nurbs_curve.project_point(path_points[1]) |
2860 | | - p = yarn_path_eval.position |
2861 | | - d = yarn_path_eval.first_derivative.normalize() |
2862 | | - |
2863 | | - # Define Hughes-Moeller algorithm for finding orthonormal base |
2864 | | - def hughes_moeller(axis_direction): |
2865 | | - """Find the orthonornal base using hughes moeller algorithm.""" |
2866 | | - n = axis_direction |
2867 | | - if np.abs(n[0]) > np.abs([n[2]]): |
2868 | | - b2 = np.array(([-n[1], n[0], 0.0])) |
2869 | | - else: |
2870 | | - b2 = np.array((0.0, -n[2], n[1])) |
2871 | | - b2 *= np.sqrt(np.dot(b2, b2)) |
2872 | | - b1 = np.cross(b2, n) |
2873 | | - return b1, b2 |
2874 | | - |
2875 | | - a = 0.043134775028197354 |
2876 | | - aspect_ratio = 0.1 |
2877 | | - p1, p2 = hughes_moeller(np.array([d.x, d.y, d.z])) |
2878 | | - plane = Plane(origin=p, direction_x=Vector3D(p1), direction_y=Vector3D(p2)) |
2879 | | - lenticular_profile = Sketch(plane) |
2880 | | - radius = (a / aspect_ratio + a * aspect_ratio) / 2.0 |
2881 | | - |
2882 | | - c1 = Point2D([-radius + a * aspect_ratio, 0.0]) |
2883 | | - c2 = Point2D([radius - a * aspect_ratio, 0.0]) |
2884 | | - s1 = Point2D([0.0, a]) |
2885 | | - e1 = Point2D([0.0, -a]) |
2886 | | - |
2887 | | - lenticular_profile.arc(s1, e1, c1, True) |
2888 | | - lenticular_profile.arc(e1, s1, c2, True) |
2889 | | - |
2890 | | - # Sweep the sketch |
2891 | | - sweep_body = design.sweep_with_guide( |
2892 | | - name="Yarn", |
2893 | | - sketch=lenticular_profile, |
2894 | | - path=[yarn_path], |
2895 | | - guide=None, |
| 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 = [SweepWithGuideData( |
| 2844 | + name="SweptBody", |
| 2845 | + parent_id=design.id, |
| 2846 | + sketch=profile_sketch, |
| 2847 | + path=trimmed_path, |
| 2848 | + guide=trimmed_guide, |
2896 | 2849 | tight_tolerance=True, |
2897 | | - ) |
| 2850 | + )] |
| 2851 | + sweep_body = design.sweep_with_guide(sweep_data=sweep_data)[0] |
| 2852 | + |
| 2853 | + design.export_to_scdocx("C:\\Users\\jkerstet\\Downloads\\sweep_body.scdocx") |
2898 | 2854 |
|
2899 | | - sweep_body.plot(screenshot="C:\\Users\\jkerstet\\Downloads\\sweep_body.png") |
| 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 |
2900 | 2861 |
|
2901 | 2862 |
|
2902 | 2863 | def test_create_body_from_loft_profile(modeler: Modeler): |
|
0 commit comments