Skip to content

Commit 0a17030

Browse files
added translate and rotate trimmed curves
1 parent edf9a45 commit 0a17030

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from ansys.geometry.core.math.matrix import Matrix44
3333
from ansys.geometry.core.math.point import Point3D
3434
from ansys.geometry.core.math.vector import Vector3D
35-
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle
35+
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance
3636
from ansys.geometry.core.shapes.curves.curve import Curve
3737
from ansys.geometry.core.shapes.curves.curve_evaluation import CurveEvaluation
3838
from ansys.geometry.core.shapes.parameterization import Interval
@@ -181,6 +181,63 @@ def transformed_copy(self, matrix: Matrix44) -> "TrimmedCurve":
181181
self.interval,
182182
self.length,
183183
)
184+
185+
def translate(self, direction: Vector3D, distance: Real | Quantity | Distance) -> None:
186+
"""Translate the trimmed curve by a given vector and distance.
187+
188+
Parameters
189+
----------
190+
direction : Vector3D
191+
Direction of translation.
192+
distance : Real | Quantity | Distance
193+
Distance to translate.
194+
"""
195+
distance = distance if isinstance(distance, Distance) else Distance(distance)
196+
translation_matrix = Matrix44.create_translation(direction * distance.value.m)
197+
198+
translated_copy = self.transformed_copy(translation_matrix)
199+
200+
# Update the current instance with the translated copy
201+
self._geometry = translated_copy.geometry
202+
self._start = translated_copy.start
203+
self._end = translated_copy.end
204+
self._length = translated_copy.length
205+
self._interval = translated_copy.interval
206+
207+
def rotate(self, origin: Point3D, axis: Vector3D, angle: Real | Quantity | Angle) -> None:
208+
"""Rotate the trimmed curve around a given axis centered at a given point.
209+
210+
Parameters
211+
----------
212+
origin : Point3D
213+
Origin point of the rotation.
214+
axis : Vector3D
215+
Axis of rotation.
216+
angle : Real | Quantity | Angle
217+
Angle to rotate in radians.
218+
"""
219+
angle = angle if isinstance(angle, Angle) else Angle(angle)
220+
221+
# Translate the curve to the origin
222+
translate_to_origin_matrix = Matrix44.create_translation(
223+
Vector3D([origin.x.m, origin.y.m, origin.z.m]))
224+
translated_copy = self.transformed_copy(translate_to_origin_matrix)
225+
226+
# Rotate the curve around the axis
227+
rotation_matrix = Matrix44.create_matrix_from_rotation_about_axis(axis, angle.value.m)
228+
rotated_copy = translated_copy.transformed_copy(rotation_matrix)
229+
230+
# Translate the curve back to its original position
231+
translate_back_matrix = Matrix44.create_translation(
232+
Vector3D([-origin.x.m, -origin.y.m, -origin.z.m]))
233+
translated_back_copy = rotated_copy.transformed_copy(translate_back_matrix)
234+
235+
# Update the current instance with the rotated copy
236+
self._geometry = translated_back_copy.geometry
237+
self._start = translated_back_copy.start
238+
self._end = translated_back_copy.end
239+
self._length = translated_back_copy.length
240+
self._interval = translated_back_copy.interval
184241

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

0 commit comments

Comments
 (0)