CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
geom
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
"
10
#include "
carla/geom/Quaternion.h
"
11
#include "
carla/geom/RightHandedRotation.h
"
12
#include "
carla/geom/RightHandedVector3D.h
"
13
14
#include <array>
15
#include <cmath>
16
17
namespace
carla
{
18
namespace
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`.
39
struct
RightHandedTransform
{
40
41
/// Translation in the right-handed frame, metres.
42
RightHandedVector3D
location
;
43
44
/// Orientation in the right-handed frame: roll, pitch, yaw in degrees,
45
/// right-hand rule, applied as intrinsic Z-Y-X.
46
RightHandedRotation
rotation
;
47
48
RightHandedTransform
() =
default
;
49
50
constexpr
RightHandedTransform
(
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)`).
65
Quaternion
GetQuaternion
()
const
{
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
Math.h
RightHandedRotation.h
RightHandedVector3D.h
carla::geom::Math::ToRadians
static constexpr T ToRadians(T deg)
Definition
Math.h:43
carla::geom::Quaternion
Quaternion representing a 3D rotation, stored as (x, y, z, w).
Definition
geom/Quaternion.h:37
carla::geom::Quaternion::Quaternion
Quaternion()=default
Quaternion.h
carla::geom
Definition
Misc.h:24
carla::road
Definition
SignComponent.h:23
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::geom::RightHandedRotation
Euler angles of a rotation expressed in a right-handed frame, in degrees.
Definition
RightHandedRotation.h:34
carla::geom::RightHandedRotation::yaw
float yaw
Rotation about the up (+Z) axis, degrees, right-hand rule.
Definition
RightHandedRotation.h:43
carla::geom::RightHandedRotation::roll
float roll
Rotation about the forward (+X) axis, degrees, right-hand rule.
Definition
RightHandedRotation.h:37
carla::geom::RightHandedRotation::pitch
float pitch
Rotation about the left (+Y) axis, degrees, right-hand rule.
Definition
RightHandedRotation.h:40
carla::geom::RightHandedTransform::GetQuaternion
Quaternion GetQuaternion() const
Orientation as a right-handed (x, y, z, w) quaternion.
Definition
RightHandedTransform.h:65
carla::geom::RightHandedTransform::location
RightHandedVector3D location
Translation in the right-handed frame, metres.
Definition
RightHandedTransform.h:42
carla::geom::RightHandedTransform::operator==
bool operator==(const RightHandedTransform &rhs) const
Definition
RightHandedTransform.h:92
carla::geom::RightHandedTransform::GetMatrix
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...
Definition
RightHandedTransform.h:77
carla::geom::RightHandedTransform::rotation
RightHandedRotation rotation
Orientation in the right-handed frame: roll, pitch, yaw in degrees, right-hand rule,...
Definition
RightHandedTransform.h:46
carla::geom::RightHandedTransform::RightHandedTransform
constexpr RightHandedTransform(const RightHandedVector3D &in_location, const RightHandedRotation &in_rotation)
Definition
RightHandedTransform.h:50
carla::geom::RightHandedTransform::operator!=
bool operator!=(const RightHandedTransform &rhs) const
Definition
RightHandedTransform.h:99
carla::geom::RightHandedTransform::RightHandedTransform
constexpr RightHandedTransform(const RightHandedVector3D &in_location)
Definition
RightHandedTransform.h:57
carla::geom::RightHandedTransform::RightHandedTransform
RightHandedTransform()=default
carla::geom::RightHandedVector3D
Internal adapter that holds a Vector3D in a right-handed coordinate frame.
Definition
RightHandedVector3D.h:19
carla::geom::RightHandedVector3D::y
float y
Definition
RightHandedVector3D.h:22
carla::geom::RightHandedVector3D::x
float x
Definition
RightHandedVector3D.h:21
carla::geom::RightHandedVector3D::z
float z
Definition
RightHandedVector3D.h:23
Generated by
1.18.0