Skip to content

Commit edf9a45

Browse files
wip - trimmed curve transform copy
1 parent 77d5848 commit edf9a45

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/ansys/geometry/core/shapes/curves/nurbs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from typing import TYPE_CHECKING, Optional
2626

2727
from beartype import beartype as check_input_types
28+
import numpy as np
2829

2930
from ansys.geometry.core.math import Matrix44, Point3D
3031
from ansys.geometry.core.math.vector import Vector3D
@@ -224,7 +225,12 @@ def transformed_copy(self, matrix: Matrix44) -> "NURBSCurve":
224225
NURBSCurve
225226
Transformed copy of the curve.
226227
"""
227-
control_points = [matrix @ point for point in self._nurbs_curve.ctrlpts]
228+
control_points = []
229+
for point in self._nurbs_curve.ctrlpts:
230+
# Transform the control point using the transformation matrix
231+
transformed_point = matrix @ np.array([*point, 1])
232+
control_points.append(Point3D(transformed_point[:3]))
233+
228234
return NURBSCurve.from_control_points(
229235
control_points,
230236
self._nurbs_curve.degree,

src/ansys/geometry/core/shapes/curves/trimmed_curve.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
# SOFTWARE.
2222
"""Trimmed curve class."""
2323

24-
import geomdl.operations as geomdl_operations
24+
import numpy as np
2525
from pint import Quantity
2626

2727
from ansys.api.geometry.v0.commands_pb2 import IntersectCurvesRequest
2828
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
2929
from ansys.geometry.core.connection.client import GrpcClient
3030
from ansys.geometry.core.connection.conversions import trimmed_curve_to_grpc_trimmed_curve
3131
from ansys.geometry.core.errors import protect_grpc
32+
from ansys.geometry.core.math.matrix import Matrix44
3233
from ansys.geometry.core.math.point import Point3D
33-
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
34+
from ansys.geometry.core.math.vector import Vector3D
35+
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle
3436
from ansys.geometry.core.shapes.curves.curve import Curve
3537
from ansys.geometry.core.shapes.curves.curve_evaluation import CurveEvaluation
3638
from ansys.geometry.core.shapes.parameterization import Interval
@@ -154,6 +156,31 @@ def intersect_curve(self, other: "TrimmedCurve") -> list[Point3D]:
154156
Point3D([point.x, point.y, point.z], unit=DEFAULT_UNITS.SERVER_LENGTH)
155157
for point in res.points
156158
]
159+
160+
def transformed_copy(self, matrix: Matrix44) -> "TrimmedCurve":
161+
"""Return a copy of the trimmed curve transformed by the given matrix.
162+
163+
Parameters
164+
----------
165+
matrix : Matrix44
166+
Transformation matrix to apply to the curve.
167+
168+
Returns
169+
-------
170+
TrimmedCurve
171+
A new trimmed curve with the transformation applied.
172+
"""
173+
transformed_geometry = self.geometry.transformed_copy(matrix)
174+
transformed_start = self.start.transform(matrix)
175+
transformed_end = self.end.transform(matrix)
176+
177+
return TrimmedCurve(
178+
transformed_geometry,
179+
transformed_start,
180+
transformed_end,
181+
self.interval,
182+
self.length,
183+
)
157184

158185
def __repr__(self) -> str:
159186
"""Represent the trimmed curve as a string."""

0 commit comments

Comments
 (0)