py3dframe.FrameTransform.transform#
- FrameTransform.transform(*, point=None, vector=None)[source]#
Transform a point or a vector from the input frame to the output frame.
If the point is provided, the method will return the coordinates of the point in the output frame. If the vector is provided, the method will return the coordinates of the vector in the output frame.
Several points / vectors can be transformed at the same time by providing a 2D numpy array with shape (3, N).
If both the point and the vector are provided, the method will raise a ValueError. If neither the point nor the vector is provided, the method will return None.
In the convention 0:
\[X_{\text{output_frame}} = R^{-1} * (X_{\text{input_frame}} - T)\]\[V_{\text{output_frame}} = R^{-1} * V_{\text{input_frame}}\]- Parameters:
point (Optional[array_like], optional) – The coordinates of the point in the input frame with shape (3, N). Default is None.
vector (Optional[array_like], optional) – The coordinates of the vector in the input frame with shape (3, N). Default is None.
- Returns:
The coordinates of the point or the vector in the output frame with shape (3, N).
- Return type:
- Raises:
ValueError – If the point or the vector is not provided. If point and vector are both provided.
Examples
Lets create a FrameTransform object with the global frame as input frame and a local frame as output frame.
import numpy as np from py3dframe import Frame, FrameTransform frame_E = Frame.canonical() # Input frame - Global frame frame_F = Frame.from_axes(origin=[1, 2, 3], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1]) # Output frame - Local frame transform = FrameTransform(input_frame=frame_E, output_frame=frame_F, dynamic=True, convention=0)
The FrameTransform object can be used to transform points or vectors from the input frame to the output frame.
X_i = np.array([1, 2, 3]).reshape((3, 1)) # Point in the input frame coordinates X_o = transform.transform(point=X_i) # Transform the point to the output frame coordinates print(X_o) # Output: [[0.] [0.] [0.]] V_i = np.array([1, 0, 0]).reshape((3, 1)) # Vector in the input frame coordinates V_o = transform.transform(vector=V_i) # Transform the vector to the output frame coordinates print(V_o) # Output: [[1.] [0.] [0.]]