18 T
b = 0,
c = 0,
d = 0;
32 [[nodiscard]]
constexpr T
angle() const noexcept {
return 2 * std::acos( std::clamp(
a, T(-1), T(1) ) ); }
36 [[nodiscard]]
constexpr T
normSq()
const {
return a *
a +
b *
b +
c *
c +
d *
d; }
37 [[nodiscard]]
constexpr T
norm()
const {
return std::sqrt(
normSq() ); }
66 auto xfA =
slerp( xf0.
A, xf1.
A, t );
67 return { xfA, ( 1 - t ) * xf0( p ) + t * xf1( p ) - xfA * p };
80 a = std::cos(
angle / 2 );
91 const auto tr = m.trace();
94 auto S = std::sqrt( tr + 1 ) * 2;
96 b = ( m.z.y - m.y.z ) / S;
97 c = ( m.x.z - m.z.x ) / S;
98 d = ( m.y.x - m.x.y ) / S;
100 else if ( m.x.x > m.y.y && m.x.x > m.z.z )
102 auto S = std::sqrt( 1 + m.x.x - m.y.y - m.z.z ) * 2;
103 a = ( m.z.y - m.y.z ) / S;
105 c = ( m.x.y + m.y.x ) / S;
106 d = ( m.x.z + m.z.x ) / S;
108 else if ( m.y.y > m.z.z )
110 auto S = std::sqrt( 1 + m.y.y - m.x.x - m.z.z ) * 2;
111 a = ( m.x.z - m.z.x ) / S;
112 b = ( m.x.y + m.y.x ) / S;
114 d = ( m.y.z + m.z.y ) / S;
118 auto S = std::sqrt( 1 + m.z.z - m.x.x - m.y.y ) * 2;
119 a = ( m.y.x - m.x.y ) / S;
120 b = ( m.x.z + m.z.x ) / S;
121 c = ( m.y.z + m.z.y ) / S;
131 auto cr =
cross( from, to );
132 if( cr.x == 0 && cr.y == 0 && cr.z == 0 )
138 a = 1; b = 0; c = 0; d = 0;
144 auto perp =
cross( from, from.furthestBasisVector() );
145 a = 0; b = perp.x; c = perp.y; d = perp.z;
151 a += std::sqrt( from.lengthSq() * to.lengthSq() );
152 b = cr.x; c = cr.y; d = cr.z;
164 T cosTheta = std::clamp(
dot( q0, q1 ), T(-1), T(1) );
168 cosTheta = -cosTheta;
170 T theta = std::acos( cosTheta );
171 T sinTheta = std::sin( theta );
173 return lerp( q0, q1, t ).normalized();
175 return std::sin( theta * ( 1 - t ) ) / sinTheta * q0 + std::sin( theta * t ) / sinTheta * q1;
182 res.
x =
Vector3<T>{ a * a + b * b - c * c - d * d, 2*(b * c - a * d), 2*(b * d + a * c) };
183 res.
y =
Vector3<T>{ 2*(b * c + a * d), a * a + c * c - b * b - d * d, 2*(c * d - a * b) };
184 res.
z =
Vector3<T>{ 2*(b * d - a * c), 2*(c * d + a * b), a * a + d * d - b * b - c * c };
191 return a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d;
203 return {a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d};
209 return {a.a - b.a, a.b - b.b, a.c - b.c, a.d - b.d};
215 return {a * b.a, a * b.b, a * b.c, a * b.d};
221 return {a * b.a, a * b.b, a * b.c, a * b.d};
227 return b * ( 1 / a );
234 return a.a *
b.a +
a.b *
b.b +
a.c *
b.c +
a.d *
b.d;
243 q1.
a * q2.
a - q1.
b * q2.
b - q1.
c * q2.
c - q1.
d * q2.
d,
244 q1.
a * q2.
b + q1.
b * q2.
a + q1.
c * q2.
d - q1.
d * q2.
c,
245 q1.
a * q2.
c - q1.
b * q2.
d + q1.
c * q2.
a + q1.
d * q2.
b,
246 q1.
a * q2.
d + q1.
b * q2.
c - q1.
c * q2.
b + q1.
d * q2.
a
254 return ( *
this *
Quaternion( T(0), p ) * this->conjugate() ).im();
301 for (
int i = 0; i < 24; ++i )
306 T cos = std::abs( relativeQuat.
a );
313 return canonQuats[closestIndex];
352 res.
b = xf( center ) - res.
A * center;
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:461
bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
static constexpr Vector3 plusX() noexcept
Definition MRVector3.h:53
static Quaternion slerp(Quaternion q0, Quaternion q1, T t)
given t in [0,1] and two unit quaternions, interpolates them spherically and produces another unit qu...
constexpr Quaternion(const Vector3< T > &from, const Vector3< T > &to) noexcept
finds shorter arc rotation quaternion from one vector to another
T d
imaginary part: b*i + c*j + d*k
Definition MRQuaternion.h:18
constexpr T norm() const
Definition MRQuaternion.h:37
constexpr Quaternion inverse() const noexcept
computes reciprocal quaternion
Definition MRQuaternion.h:48
T dot(const Quaternion< T > &a, const Quaternion< T > &b)
dot product
Definition MRQuaternion.h:232
static Matrix3< T > slerp(const Matrix3< T > &m0, const Matrix3< T > &m1, T t)
given t in [0,1] and two rotation matrices, interpolates them spherically and produces another rotati...
Definition MRQuaternion.h:61
Matrix3< T > orthonormalized(const Matrix3< T > &m)
given any matrix, returns a close rotation matrix
Definition MRQuaternion.h:340
constexpr Quaternion(const Vector3< T > &axis, T angle) noexcept
T c
Definition MRQuaternion.h:18
Vector3< T > x
rows, identity matrix by default
Definition MRMatrix3.h:29
auto dot(const Matrix2< T > &a, const Matrix2< T > &b) -> decltype(dot(a.x, b.x))
double-dot product: x = a : b
Definition MRMatrix2.h:142
AffineXf3< T > orthonormalized(const AffineXf3< T > &xf, const Vector3< T > ¢er={})
Definition MRQuaternion.h:348
angle
Definition MRObjectDimensionsEnum.h:16
static Quaternion lerp(const Quaternion &q0, const Quaternion &q1, T t)
given t in [0,1], interpolates linearly two quaternions giving in general not-unit quaternion
Definition MRQuaternion.h:57
constexpr Vector3< T > axis() const noexcept
returns axis of rotation encoded in this quaternion
Definition MRQuaternion.h:34
constexpr Quaternion(const Matrix3< T > &m)
T y
Definition MRVector3.h:39
bool operator!=(const Color &a, const Color &b)
Definition MRColor.h:104
constexpr Quaternion(T real, const Vector3< T > &im) noexcept
Definition MRQuaternion.h:23
Matrix3< T > slerp(const Matrix3< T > &m0, const Matrix3< T > &m1, T t)
given t in [0,1] and two rotation matrices, interpolates them spherically and produces another rotati...
Definition MRQuaternion.h:325
Color operator/(const Color &b, float a)
Definition MRColor.h:129
constexpr Quaternion operator-() const
returns quaternion representing the same rotation, using the opposite rotation direction and opposite...
Definition MRQuaternion.h:39
Quaternion & operator*=(T s)
Definition MRQuaternion.h:70
Quaternion
Definition MRMeshFwd.h:460
Color operator*(float a, const Color &b)
Definition MRColor.h:119
Quaternion & operator/=(T s)
Definition MRQuaternion.h:71
const Quaternion< T > * getCanonicalQuaternions() noexcept
Definition MRQuaternion.h:258
constexpr Quaternion conjugate() const noexcept
computes conjugate quaternion, which for unit quaternions encodes the opposite rotation
Definition MRQuaternion.h:46
constexpr Quaternion() noexcept=default
Quaternion normalized() const
Definition MRQuaternion.h:43
T a
real part of the quaternion
Definition MRQuaternion.h:17
T b
Definition MRQuaternion.h:18
Matrix3
Definition MRMeshFwd.h:251
constexpr Vector3< T > im() const noexcept
returns imaginary part of the quaternion as a vector
Definition MRQuaternion.h:29
Quaternion< T > getClosestCanonicalQuaternion(const Quaternion< T > &base) noexcept
returns closest to base canonical quaternion
Definition MRQuaternion.h:295
static AffineXf3< T > slerp(const AffineXf3< T > &xf0, const AffineXf3< T > &xf1, T t, const Vector3< T > &p={})
Definition MRQuaternion.h:64
static constexpr Vector3 plusZ() noexcept
Definition MRVector3.h:55
V b
Definition MRAffineXf.h:31
constexpr auto lerp(V v0, V v1, T t) noexcept
Linear interpolation: returns v0 when t==0 and v1 when t==1.
Definition MRMeshFwd.h:779
constexpr T angle() const noexcept
returns angle of rotation encoded in this quaternion
Definition MRQuaternion.h:32
M A
Definition MRAffineXf.h:30
MRMESH_CLASS Vector3
Definition MRMeshFwd.h:218
AffineXf< Vector3< T > > AffineXf3
Definition MRMeshFwd.h:313
void normalize()
scales this quaternion to make its norm unit
Definition MRQuaternion.h:42
constexpr T normSq() const
Definition MRQuaternion.h:36
AffineXf3< T > slerp(const AffineXf3< T > &xf0, const AffineXf3< T > &xf1, T t, const Vector3< T > &p={})
Definition MRQuaternion.h:333
T z
Definition MRVector3.h:39
static constexpr Vector3 plusY() noexcept
Definition MRVector3.h:54
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:109
constexpr Vector3< T > operator()(const Vector3< T > &p) const noexcept
constexpr A normalize(A a)
Definition MRImGuiVectorOperators.h:134
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix3.h:24
Definition MRQuaternion.h:16
T cross(const Vector2< T > &a, const Vector2< T > &b)
cross product
Definition MRVector2.h:160
Definition MRVector3.h:33