-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor euler and quaternion conversion functions #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,18 +8,18 @@ def ssa(angle: float) -> float: | |
| return (angle + np.pi) % (2 * np.pi) - np.pi | ||
|
|
||
|
|
||
| def euler_to_quat(roll: float, pitch: float, yaw: float) -> np.ndarray: | ||
| """Converts euler angles to quaternion (x, y, z, w).""" | ||
| rotation_matrix = Rotation.from_euler("XYZ", [roll, pitch, yaw]).as_matrix() | ||
| quaternion = Rotation.from_matrix(rotation_matrix).as_quat() | ||
| return quaternion | ||
|
|
||
|
|
||
| def quat_to_euler(x: float, y: float, z: float, w: float) -> np.ndarray: | ||
| """Converts quaternion (x, y, z, w) to euler angles.""" | ||
| rotation_matrix = Rotation.from_quat([x, y, z, w]).as_matrix() | ||
| euler_angles = Rotation.from_matrix(rotation_matrix).as_euler("XYZ") | ||
| return euler_angles | ||
| def euler_to_quat( | ||
| roll: float, pitch: float, yaw: float, *, degrees: bool = False | ||
| ) -> np.ndarray: | ||
| """RPY (intrinsic x-y-z) -> quaternion (x, y, z, w).""" | ||
| return Rotation.from_euler('xyz', [roll, pitch, yaw], degrees=degrees).as_quat() | ||
|
|
||
|
|
||
| def quat_to_euler( | ||
| x: float, y: float, z: float, w: float, *, degrees: bool = False | ||
| ) -> np.ndarray: | ||
| """Quaternion (x, y, z, w) -> RPY (intrinsic x-y-z).""" | ||
| return Rotation.from_quat([x, y, z, w]).as_euler('xyz', degrees=degrees) | ||
|
||
|
|
||
|
|
||
| @dataclass(slots=True) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The euler sequence changed from 'XYZ' (extrinsic) to 'xyz' (intrinsic) without clear documentation of this breaking change. This affects the rotation order and could break existing code that depends on the previous behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nobody uses my code anyway