57 constexpr Quaternion(
float ix,
float iy,
float iz,
float iw)
68 const float half_yaw_rad =
69 static_cast<float>(Math::ToRadians<double>(rotation.
yaw)) * 0.5f;
70 const float half_pitch_rad =
71 static_cast<float>(Math::ToRadians<double>(rotation.
pitch)) * 0.5f;
72 const float half_roll_rad =
73 static_cast<float>(Math::ToRadians<double>(rotation.
roll)) * 0.5f;
75 const float cy = std::cos(half_yaw_rad);
76 const float sy = std::sin(half_yaw_rad);
77 const float cp = std::cos(half_pitch_rad);
78 const float sp = std::sin(half_pitch_rad);
79 const float cr = std::cos(half_roll_rad);
80 const float sr = std::sin(half_roll_rad);
82 w =
cr * cp * cy + sr * sp * sy;
83 x = sr * cp * cy -
cr * sp * sy;
84 y =
cr * sp * cy + sr * cp * sy;
85 z =
cr * cp * sy - sr * sp * cy;
105 const float sin_pitch = 2.0f * (
w *
y -
z *
x);
106 const float clamped_sin_pitch =
107 (sin_pitch > 1.0f) ? 1.0f : (sin_pitch < -1.0f) ? -1.0f : sin_pitch;
108 const float pitch_rad = std::asin(clamped_sin_pitch);
110 const float roll_rad = std::atan2(
111 2.0f * (
w *
x +
y *
z),
112 1.0f - 2.0f * (
x *
x +
y *
y));
113 const float yaw_rad = std::atan2(
114 2.0f * (
w *
z +
x *
y),
115 1.0f - 2.0f * (
y *
y +
z *
z));
118 static_cast<float>(Math::ToDegrees<double>(roll_rad)),
119 static_cast<float>(Math::ToDegrees<double>(pitch_rad)),
120 static_cast<float>(Math::ToDegrees<double>(yaw_rad)));
127 const float sin_pitch = 2.0f * (
w *
y -
z *
x);
128 const float clamped_sin_pitch =
129 (sin_pitch > 1.0f) ? 1.0f : (sin_pitch < -1.0f) ? -1.0f : sin_pitch;
130 const float pitch_rad = std::asin(clamped_sin_pitch);
132 const float roll_rad = std::atan2(
133 2.0f * (
w *
x +
y *
z),
134 1.0f - 2.0f * (
x *
x +
y *
y));
135 const float yaw_rad = std::atan2(
136 2.0f * (
w *
z +
x *
y),
137 1.0f - 2.0f * (
y *
y +
z *
z));
140 static_cast<float>(Math::ToDegrees<double>(roll_rad)),
141 static_cast<float>(Math::ToDegrees<double>(pitch_rad)),
142 static_cast<float>(Math::ToDegrees<double>(yaw_rad))));
149 const float tx = 2.0f * (
y * in.
z -
z * in.
y);
150 const float ty = 2.0f * (
z * in.
x -
x * in.
z);
151 const float tz = 2.0f * (
x * in.
y -
y * in.
x);
153 const float cx =
y * tz -
z * ty;
154 const float cy =
z * tx -
x * tz;
155 const float cz =
x * ty -
y * tx;
197 const float n2 =
x *
x +
y *
y +
z *
z +
w *
w;
201 const float k = 1.0f / n2;
206 return std::sqrt(
x *
x +
y *
y +
z *
z +
w *
w);
210 const float length =
Length();
211 if (length <= 0.0f) {
214 const float k = 1.0f / length;
221 w * rhs.
x +
x * rhs.
w +
y * rhs.
z -
z * rhs.
y,
222 w * rhs.
y -
x * rhs.
z +
y * rhs.
w +
z * rhs.
x,
223 w * rhs.
z +
x * rhs.
y -
y * rhs.
x +
z * rhs.
w,
224 w * rhs.
w -
x * rhs.
x -
y * rhs.
y -
z * rhs.
z);
232 return (
x == rhs.
x) && (
y == rhs.
y) && (
z == rhs.
z) && (
w == rhs.
w);
236 return !(*
this == rhs);
Quaternion representing a 3D rotation, stored as (x, y, z, w).
bool operator!=(const Quaternion &rhs) const
bool operator==(const Quaternion &rhs) const
Quaternion Conjugate() const
Conjugate of this quaternion.
Vector3D GetRightVector() const
Unit vector pointing toward the local Y axis of this rotation, expressed in CARLA's left-handed frame...
Rotation Rotator() const
Convert this quaternion back to a CARLA (left-handed) Euler rotation.
RightHandedRotation ToRightHandedRotation() const
This rotation as right-handed (FLU) Euler angles, degrees, intrinsic Z-Y-X.
Quaternion UnitQuaternion() const
constexpr Quaternion(float ix, float iy, float iz, float iw)
Quaternion(const RightHandedRotation &rotation)
Quaternion of a right-handed (FLU) Euler triple, degrees, intrinsic Z-Y-X: q = qz(yaw) * qy(pitch) * ...
Vector3D GetForwardVector() const
Unit vector pointing toward the local X axis of this rotation, expressed in CARLA's left-handed frame...
RightHandedVector3D InverseRotatedVector(const RightHandedVector3D &in) const
Inverse rotation of a right-handed vector.
Quaternion operator*(const Quaternion &rhs) const
Hamilton product (*this) * rhs.
RightHandedVector3D RotatedVector(const RightHandedVector3D &in) const
Rotate a right-handed vector by this quaternion.
MSGPACK_DEFINE_ARRAY(x, y, z, w)
Quaternion Inverse() const
Inverse of this quaternion (assumes non-zero norm).
Vector3D GetUpVector() const
Unit vector pointing toward the local Z axis of this rotation, expressed in CARLA's left-handed frame...
Quaternion(const Rotation &rotation)
Quaternion of a CARLA (left-handed) Euler rotation, degrees.
Euler angles of a rotation in CARLA's / Unreal's left-handed frame: x forward, y right,...
static constexpr Rotation FromRightHanded(const RightHandedRotation &rhs)
Inverse of ToRightHanded().
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.
Internal adapter that holds a Vector3D in a right-handed coordinate frame.