Transforms in 2D¶
Functions for converting SE(2) poses (x, y, yaw) and 2D points (x, y)
between coordinate frames. For the 3D counterpart see Transforms in 3D.
Convert SE2 poses between frames¶
Convert between absolute and relative coordinates:
abs_to_rel_se2_array()/abs_to_rel_se2()– absolute → relative: \(T_\text{rel} = T_\text{origin}^{-1} \cdot T_\text{abs}\)rel_to_abs_se2_array()/rel_to_abs_se2()– relative → absolute: \(T_\text{abs} = T_\text{origin} \cdot T_\text{rel}\)reframe_se2_array()/reframe_se2()– re-express poses from one reference frame to another.
- py123d.geometry.transform.abs_to_rel_se2_array(origin, pose_se2_array)[source]¶
Convert an SE2 array from absolute to relative coordinates.
Computes \(T_\text{rel} = T_\text{origin}^{-1} \cdot T_\text{abs}\) for each pose in the array.
Example:
>>> origin = PoseSE2(1.0, 2.0, np.pi / 2) >>> poses = np.array([[3.0, 4.0, 0.0]], dtype=np.float64) >>> rel = abs_to_rel_se2_array(origin, poses)
- Parameters:
- Return type:
- Returns:
SE2 array in relative coordinates with the same shape as pose_se2_array.
- py123d.geometry.transform.abs_to_rel_se2(origin, pose_se2)[source]¶
Convert a single SE2 pose from absolute to relative coordinates.
Typed wrapper around
abs_to_rel_se2_array().Computes \(T_\text{rel} = T_\text{origin}^{-1} \cdot T_\text{abs}\).
Example:
>>> origin = PoseSE2(1.0, 1.0, 0.0) >>> pose = PoseSE2(2.0, 3.0, 0.0) >>> rel = abs_to_rel_se2(origin, pose) # PoseSE2(1.0, 2.0, 0.0)
- py123d.geometry.transform.rel_to_abs_se2_array(origin, pose_se2_array)[source]¶
Convert an SE2 array from relative to absolute coordinates.
Computes \(T_\text{abs} = T_\text{origin} \cdot T_\text{rel}\) for each pose in the array.
Example:
>>> origin = PoseSE2(1.0, 1.0, 0.0) >>> rel_poses = np.array([[1.0, 1.0, 0.0]], dtype=np.float64) >>> abs_poses = rel_to_abs_se2_array(origin, rel_poses) # [[2.0, 2.0, 0.0]]
- Parameters:
- Return type:
- Returns:
SE2 array in absolute coordinates with the same shape as pose_se2_array.
- py123d.geometry.transform.rel_to_abs_se2(origin, pose_se2)[source]¶
Convert a single SE2 pose from relative to absolute coordinates.
Typed wrapper around
rel_to_abs_se2_array().Computes \(T_\text{abs} = T_\text{origin} \cdot T_\text{rel}\).
Example:
>>> origin = PoseSE2(1.0, 1.0, 0.0) >>> rel = PoseSE2(1.0, 1.0, 0.0) >>> abs_pose = rel_to_abs_se2(origin, rel) # PoseSE2(2.0, 2.0, 0.0)
- py123d.geometry.transform.reframe_se2_array(from_origin, to_origin, pose_se2_array)[source]¶
Convert an SE2 array from one reference frame to another.
Equivalent to converting from the source frame to absolute coordinates, then from absolute coordinates to the target frame:
abs_to_rel(to_origin, rel_to_abs(from_origin, poses)).Example:
>>> frame_a = PoseSE2(1.0, 0.0, 0.0) >>> frame_b = PoseSE2(0.0, 1.0, np.pi / 2) >>> poses_in_a = np.array([[1.0, 0.0, 0.0]], dtype=np.float64) >>> poses_in_b = reframe_se2_array(frame_a, frame_b, poses_in_a)
- Parameters:
from_origin (
Union[PoseSE2,ndarray[tuple[Any,...],dtype[float64]]]) – The source origin state in the absolute frame.to_origin (
Union[PoseSE2,ndarray[tuple[Any,...],dtype[float64]]]) – The target origin state in the absolute frame.pose_se2_array (
ndarray[tuple[Any,...],dtype[float64]]) – Array of SE2 poses in the source frame with shape(..., 3).
- Raises:
- Return type:
- Returns:
The SE2 array in the target frame, indexed by
PoseSE2Index.
- py123d.geometry.transform.reframe_se2(from_origin, to_origin, pose_se2)[source]¶
Convert a single SE2 pose from one reference frame to another.
Typed wrapper around
reframe_se2_array().
Convert 2D points between frames¶
The same absolute/relative/reframe operations, applied to 2D points instead of SE2 poses:
- py123d.geometry.transform.abs_to_rel_points_2d_array(origin, points_2d_array)[source]¶
Convert a 2D point array from absolute to relative coordinates.
Computes \(p_\text{rel} = R_\text{origin}^T \cdot (p_\text{abs} - t_\text{origin})\) for each point in the array.
Example:
>>> origin = PoseSE2(1.0, 1.0, 0.0) >>> points = np.array([[2.0, 2.0], [0.0, 1.0]], dtype=np.float64) >>> rel_points = abs_to_rel_points_2d_array(origin, points) # [[1.0, 1.0], [-1.0, 0.0]]
- Parameters:
- Return type:
- Returns:
2D points in relative coordinates with the same shape as points_2d_array.
- py123d.geometry.transform.abs_to_rel_point_2d(origin, point_2d)[source]¶
Convert a single 2D point from absolute to relative coordinates.
Typed wrapper around
abs_to_rel_points_2d_array().Computes \(p_\text{rel} = R_\text{origin}^T \cdot (p_\text{abs} - t_\text{origin})\).
- py123d.geometry.transform.rel_to_abs_points_2d_array(origin, points_2d_array)[source]¶
Convert a relative 2D point array to absolute coordinates.
Computes \(p_\text{abs} = R_\text{origin} \cdot p_\text{rel} + t_\text{origin}\) for each point in the array.
- Parameters:
- Return type:
- Returns:
2D points in absolute coordinates with the same shape as points_2d_array.
- py123d.geometry.transform.rel_to_abs_point_2d(origin, point_2d)[source]¶
Convert a single 2D point from relative to absolute coordinates.
Typed wrapper around
rel_to_abs_points_2d_array().Computes \(p_\text{abs} = R_\text{origin} \cdot p_\text{rel} + t_\text{origin}\).
- py123d.geometry.transform.reframe_points_2d_array(from_origin, to_origin, points_2d_array)[source]¶
Convert 2D points from one reference frame to another.
Equivalent to converting from the source frame to absolute coordinates, then from absolute coordinates to the target frame.
- Parameters:
from_origin (
Union[PoseSE2,ndarray[tuple[Any,...],dtype[float64]]]) – The source origin state in the absolute frame.to_origin (
Union[PoseSE2,ndarray[tuple[Any,...],dtype[float64]]]) – The target origin state in the absolute frame.points_2d_array (
ndarray[tuple[Any,...],dtype[float64]]) – Array of 2D points in the source frame with shape(..., 2).
- Raises:
- Return type:
- Returns:
The 2D points in the target frame, indexed by
Point2DIndex.
- py123d.geometry.transform.reframe_point_2d(from_origin, to_origin, point_2d)[source]¶
Convert a single 2D point from one reference frame to another.
Typed wrapper around
reframe_points_2d_array().
Translation along body-frame axes¶
Translate SE2 poses or 2D points along their local (body) coordinate axes. The yaw / orientation is preserved.
- py123d.geometry.transform.translate_se2_along_body_frame(pose_se2, translation)[source]¶
Translate a single SE2 state along its body frame.
Typed wrapper around
translate_se2_array_along_body_frame().
- py123d.geometry.transform.translate_se2_along_x(pose_se2, distance)[source]¶
Translate a single SE2 state along its local X-axis (forward direction).
Shorthand for
translate_se2_along_body_frame(pose_se2, Vector2D(distance, 0.0)).
- py123d.geometry.transform.translate_se2_along_y(pose_se2, distance)[source]¶
Translate a single SE2 state along its local Y-axis (left direction).
Shorthand for
translate_se2_along_body_frame(pose_se2, Vector2D(0.0, distance)).
- py123d.geometry.transform.translate_se2_array_along_body_frame(pose_se2_array, translation)[source]¶
Translate an array of SE2 states along their respective body frames.
Each pose is translated by the same translation vector, expressed in its local coordinate frame (x: forward, y: left). The yaw component is unchanged.
Example:
>>> poses = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, np.pi / 2]], dtype=np.float64) >>> translated = translate_se2_array_along_body_frame(poses, Vector2D(1.0, 0.0)) >>> # First pose moves +1 in x; second pose (rotated 90 deg) moves +1 in y.
- Parameters:
- Return type:
- Returns:
Translated SE2 array with the same shape as pose_se2_array.
- py123d.geometry.transform.translate_2d_along_body_frame(points_2d, yaws, x_translate, y_translate)[source]¶
Translate 2D points along their respective body frames.
Unlike
translate_se2_array_along_body_frame(), this function accepts separate arrays for orientations and per-point translation distances, which is useful when each point has a different translation.- Parameters:
points_2d (
ndarray[tuple[Any,...],dtype[float64]]) – Array of 2D points, indexed byPoint2DIndex.yaws (
ndarray[tuple[Any,...],dtype[float64]]) – Array of yaw angles (one per point).x_translate (
ndarray[tuple[Any,...],dtype[float64]]) – Array of x (forward) translations.y_translate (
ndarray[tuple[Any,...],dtype[float64]]) – Array of y (left) translations.
- Return type:
- Returns:
Array of translated 2D points, indexed by
Point2DIndex.