py3dframe.translate_along_axis#
- translate_along_axis(frame, axis, distance, use_global=False, inplace=True)[source]#
Translate a frame along a specified axis by a given distance.
The origin of the frame is moved along the specified axis by the given distance.
If
use_globalis set to True, the translation is applied in the global coordinate system. Otherwise, the translation is applied in the local coordinate system of the frame (in the parent frame).\[\text{new\_origin} = \text{origin} + d \cdot \hat{a}\]where \(d\) is the distance to translate, and \(\hat{a}\) is the normalized axis vector.
See also
py3dframe.Frame: for more information about the Frame class.py3dframe.rotate_around_axis(): to rotate a frame around a specific axis.py3dframe.translate(): to translate a frame by given offsets along each axis.
- Parameters:
frame (Frame) – The frame to translate.
axis (numpy.ndarray) – A 3D vector representing the axis along which to translate the frame. The vector not need to be normalized.
distance (float) – The distance to translate along the specified axis.
use_global (bool, optional) – If True, the translation is applied in the global coordinate system. If False, the translation is applied in the local coordinate system of the frame. Default is False.
inplace (bool, optional) – If True, the translation is applied to the input frame and the same frame is returned. If False, a new translated frame is returned and the input frame remains unchanged. Default is True.
- Returns:
The translated frame.
- Return type:
Examples
from py3dframe import Frame from py3dframe import translate_along_axis import numpy as np # Create a default frame frame = Frame.canonical() # Define an axis to translate along (e.g., the y-axis) axis = np.array([0.0, 1.0, 0.0]) # Translate the frame by 5 units along the specified axis in the local coordinate system translated_frame = translate_along_axis(frame, axis, distance=5.0, use_global=False, inplace=True) # The origin of the translated frame is now at (0.0, 5.0, 0.0) in the local coordinate system print(translated_frame.origin) # Output: [0. 5. 0.]