CARLA
Loading...
Searching...
No Matches
RightHandedTransform.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/geom/Math.h"
13
14#include <array>
15#include <cmath>
16
17namespace carla {
18namespace geom {
19
20 /// A rigid transform expressed in a **right-handed** frame: x forward,
21 /// y **left**, z up (ROS REP-103 "FLU"), metres and degrees.
22 ///
23 /// This is the explicit boundary type between CARLA's left-handed world and
24 /// every right-handed consumer (ROS 2 / tf2, NVIDIA ClipGT rigs, scipy,
25 /// Open3D, ...). Build one with `Transform::ToRightHanded()` and go back
26 /// with `Transform::FromRightHanded()`; the handedness change then happens
27 /// exactly once, here, instead of being sprinkled over call sites.
28 ///
29 /// Relative to the corresponding `Transform`, with `S = diag(1, -1, 1)`:
30 ///
31 /// * `location = (x, -y, z)`
32 /// * `rotation = (roll, -pitch, -yaw)`, intrinsic Z-Y-X, right-hand rule
33 /// * `GetMatrix() == S * Transform::GetMatrix() * S` (with the 4x4 `S`)
34 ///
35 /// Example: `Rotation(pitch=20, yaw=30, roll=10)` maps to
36 /// `RightHandedRotation(roll=10, pitch=-20, yaw=-30)`.
37 ///
38 /// See `Docs/coordinate_conventions.md`.
40
41 /// Translation in the right-handed frame, metres.
43
44 /// Orientation in the right-handed frame: roll, pitch, yaw in degrees,
45 /// right-hand rule, applied as intrinsic Z-Y-X.
47
49
51 const RightHandedVector3D &in_location,
52 const RightHandedRotation &in_rotation)
53 : location(in_location),
54 rotation(in_rotation) {
55 }
56
57 explicit constexpr RightHandedTransform(const RightHandedVector3D &in_location)
58 : location(in_location),
59 rotation() {
60 }
61
62 /// Orientation as a right-handed `(x, y, z, w)` quaternion. Identical to
63 /// what `ros2::TransformFromCarlaRotation` publishes for the equivalent
64 /// CARLA rotation (that helper orders the components `(w, x, y, z)`).
66 return Quaternion(rotation);
67 }
68
69 /// Row-major 4x4 pose matrix in the right-handed frame,
70 /// `R = Rz(yaw) * Ry(pitch) * Rx(roll)` with the standard right-handed
71 /// elementary matrices and `location` in the last column.
72 ///
73 /// Equal, element for element, to `S * Transform::GetMatrix() * S` with
74 /// `S = diag(1, -1, 1, 1)` -- the similarity transform that mirrors the Y
75 /// axis. That identity is pinned by
76 /// `test_geom.cpp::right_handed_matrix_is_s_m_s`.
77 std::array<float, 16> GetMatrix() const {
78 const float cy = std::cos(Math::ToRadians(rotation.yaw));
79 const float sy = std::sin(Math::ToRadians(rotation.yaw));
80 const float cp = std::cos(Math::ToRadians(rotation.pitch));
81 const float sp = std::sin(Math::ToRadians(rotation.pitch));
82 const float cr = std::cos(Math::ToRadians(rotation.roll));
83 const float sr = std::sin(Math::ToRadians(rotation.roll));
84
85 return {
86 cy * cp, cy * sp * sr - sy * cr, cy * sp * cr + sy * sr, location.x,
87 sy * cp, sy * sp * sr + cy * cr, sy * sp * cr - cy * sr, location.y,
88 -sp, cp * sr, cp * cr, location.z,
89 0.0f, 0.0f, 0.0f, 1.0f};
90 }
91
92 bool operator==(const RightHandedTransform &rhs) const {
93 return (location.x == rhs.location.x) &&
94 (location.y == rhs.location.y) &&
95 (location.z == rhs.location.z) &&
96 (rotation == rhs.rotation);
97 }
98
99 bool operator!=(const RightHandedTransform &rhs) const {
100 return !(*this == rhs);
101 }
102 };
103
104} // namespace geom
105} // namespace carla
static constexpr T ToRadians(T deg)
Definition Math.h:43
Quaternion representing a 3D rotation, stored as (x, y, z, w).
This file contains definitions of common data structures used in traffic manager.
Euler angles of a rotation expressed in a right-handed frame, in degrees.
float yaw
Rotation about the up (+Z) axis, degrees, right-hand rule.
float roll
Rotation about the forward (+X) axis, degrees, right-hand rule.
float pitch
Rotation about the left (+Y) axis, degrees, right-hand rule.
A rigid transform expressed in a right-handed frame: x forward, y left, z up (ROS REP-103 "FLU"),...
Quaternion GetQuaternion() const
Orientation as a right-handed (x, y, z, w) quaternion.
RightHandedVector3D location
Translation in the right-handed frame, metres.
bool operator==(const RightHandedTransform &rhs) const
std::array< float, 16 > GetMatrix() const
Row-major 4x4 pose matrix in the right-handed frame, R = Rz(yaw) * Ry(pitch) * Rx(roll) with the stan...
RightHandedRotation rotation
Orientation in the right-handed frame: roll, pitch, yaw in degrees, right-hand rule,...
constexpr RightHandedTransform(const RightHandedVector3D &in_location, const RightHandedRotation &in_rotation)
bool operator!=(const RightHandedTransform &rhs) const
constexpr RightHandedTransform(const RightHandedVector3D &in_location)
Internal adapter that holds a Vector3D in a right-handed coordinate frame.