115 assert(result.IsUnit(0.00001));
171 return result >= 0 ? result : result + mod;
207 return {
x*other,
y*other };
212 return {
x*other,
y*other,
z*other };
217 return {
x + other.
x,
y + other.
y };
222 return {
x - other.
x,
y - other.
y };
227 return {
x - other.
x,
y - other.
y,
z - other.
z };
233 y*other.
z -
z*other.
y,
234 -(
x*other.
z -
z*other.
x),
235 x*other.
y -
y*other.
x,
242 x*other.
x,
x*other.
y,
x*other.
z,
243 y*other.
x,
y*other.
y,
y*other.
z,
244 z*other.
x,
z*other.
y,
z*other.
z
251 x*other.
At(0,0) +
y*other.
At(0,1) +
z*other.
At(0,2),
252 x*other.
At(1,0) +
y*other.
At(1,1) +
z*other.
At(1,2),
253 x*other.
At(2,0) +
y*other.
At(2,1) +
z*other.
At(2,2),
264 return {
At(0,j),
At(1,j),
At(2,j)};
269 return {
At(i,0),
At(i,1),
At(i,2)};
275 At(0,0)+other.
At(0,0),
At(0,1)+other.
At(0,1),
At(0,2)+other.
At(0,2),
276 At(1,0)+other.
At(1,0),
At(1,1)+other.
At(1,1),
At(1,2)+other.
At(1,2),
277 At(2,0)+other.
At(2,0),
At(2,1)+other.
At(2,1),
At(2,2)+other.
At(2,2)
283 #define _MATMUL_ENTRY(row, col) At(row,0)*other.At(0,col) + At(row,1)*other.At(1,col) + At(row,2)*other.At(2,col)
295 vec.
x*
At(0,0) + vec.
y*
At(0,1) + vec.
z*
At(0,2),
296 vec.
x*
At(1,0) + vec.
y*
At(1,1) + vec.
z*
At(1,2),
297 vec.
x*
At(2,0) + vec.
y*
At(2,1) + vec.
z*
At(2,2),
304 s*
At(0,0), s*
At(0,1), s*
At(0,2),
305 s*
At(1,0), s*
At(1,1), s*
At(1,2),
306 s*
At(2,0), s*
At(2,1), s*
At(2,2)
313 At(0,0),
At(1,0),
At(2,0),
314 At(0,1),
At(1,1),
At(2,1),
315 At(0,2),
At(1,2),
At(2,2),
321 return At(0,0) +
At(1,1) +
At(2,2);
326 return (
At(0,0) * (
At(1,1)*
At(2,2) -
At(2,1)*
At(1,2))) - (
At(0,1) * (
At(1,0)*
At(2,2) -
At(2,0)*
At(1,2))) + (
At(0,2) * (
At(1,0)*
At(2,1) -
At(2,0)*
At(1,1)));
335 At(1,1)*
At(2,2) -
At(1,2)*
At(2,1),
At(0,2)*
At(2,1) -
At(0,1)*
At(2,2),
At(0,1)*
At(1,2) -
At(0,2)*
At(1,1),
336 At(1,2)*
At(2,0) -
At(1,0)*
At(2,2),
At(0,0)*
At(2,2) -
At(0,2)*
At(2,0),
At(0,2)*
At(1,0) -
At(0,0)*
At(1,2),
337 At(1,0)*
At(2,1) -
At(1,1)*
At(2,0),
At(0,1)*
At(2,0) -
At(0,0)*
At(2,1),
At(0,0)*
At(1,1) -
At(0,1)*
At(1,0)
349 : type(AttitudeType::QuaternionType), quaternion(quat) {}
352 : type(AttitudeType::DCMType), dcm(matrix) {}
383 bool rotateClockwise = oldYAxis.
CrossProduct(newYAxis) * newXAxis > 0;
392 return xAlign*yAlign;
398 case AttitudeType::QuaternionType:
400 case AttitudeType::DCMType:
410 case AttitudeType::DCMType:
412 case AttitudeType::QuaternionType:
422 case AttitudeType::DCMType:
424 case AttitudeType::QuaternionType:
425 return quaternion.
Rotate(vec);
434 case AttitudeType::DCMType:
436 case AttitudeType::QuaternionType:
445 case AttitudeType::DCMType:
446 case AttitudeType::QuaternionType:
455 SerializePrimitive<decimal>(ser, vec.
x);
456 SerializePrimitive<decimal>(ser, vec.
y);
457 SerializePrimitive<decimal>(ser, vec.
z);
462 DeserializePrimitive<decimal>(des),
463 DeserializePrimitive<decimal>(des),
464 DeserializePrimitive<decimal>(des),
#define _MATMUL_ENTRY(row, col)
EulerAngles ToSpherical() const
Get the euler angles from the attitude, converting from whatever format is stored.
Vec3 Rotate(const Vec3 &) const
Convert a vector from the reference frame to the body frame.
Mat3 GetDCM() const
Get the rotation matrix (direction cosine matrix) representing the attitude, converting from whatever...
Attitude()=default
constructs unknown attitude:
Quaternion GetQuaternion() const
Get the quaternion representing the attitude, converting from whatever format is stored.
A "human-readable" way to represent a 3d rotation or orientation.
3x3 vector with decimaling point components
Mat3 Inverse() const
Inverse of a matrix.
Vec3 Column(int) const
Get the column at index j.
Vec3 Row(int) const
Get the row at index i.
decimal Det() const
Determinant of a matrix.
Mat3 Transpose() const
Transpose of a matrix.
decimal Trace() const
Trace of a matrix.
decimal At(int i, int j) const
Access the i,j-th element of the matrix.
Mat3 operator+(const Mat3 &) const
Normal matrix addition.
Mat3 operator*(const Mat3 &) const
Naive matrix multiplication.
A quaternion is a common way to represent a 3d rotation.
Quaternion Canonicalize() const
Ensure that the quaternion's real part is nonnegative.
Vec3 Vector() const
The vector formed by imaginary components of the quaternion. The axis of the represented rotation.
decimal Angle() const
How many radians the rotation represented by this quaternion has.
EulerAngles ToSpherical() const
Vec3 Rotate(const Vec3 &) const
Rotate a 3d vector according to the rotation represented by the quaternion.
Quaternion Conjugate() const
Effectively computes a quaternion representing the inverse rotation of the original.
void SetVector(const Vec3 &)
Set imaginary components.
Quaternion operator*(const Quaternion &other) const
Multiply two quaternions using the usual definition of quaternion multiplication (effectively compose...
bool IsUnit(decimal tolerance) const
Whether the quaternion is a unit quaternion. All quaternions representing rotations should be units.
decimal SmallestAngle() const
Returns the smallest angle that can be used to represent the rotation represented by the quaternion.
Three dimensional vector with decimaling point components.
Vec3 Normalize() const
Create a vector pointing in the same direction with magnitude 1.
decimal MagnitudeSq() const
The square of the magnitude.
Mat3 OuterProduct(const Vec3 &) const
The outer product of two vectors.
decimal operator*(const Vec3 &) const
Dot product.
Vec3 CrossProduct(const Vec3 &) const
Usual vector cross product.
decimal Magnitude() const
Vec3 operator-(const Vec3 &) const
Usual vector subtraction.
#define DECIMAL_FMA(x, y, z)
#define DECIMAL_HYPOT(x, y)
#define DECIMAL_ATAN2(x, y)
Mat3 QuaternionToDCM(const Quaternion &quat)
Convert a quaternion to a rotation matrix (Direction Cosine Matrix)
decimal RadToArcSec(decimal rad)
decimal ArcSecToRad(decimal arcSec)
void SpatialToSpherical(const Vec3 &vec, decimal *ra, decimal *de)
Convert from a 3d point on the unit sphere to right ascension & declination.
decimal AngleUnit(const Vec3 &vec1, const Vec3 &vec2)
Calculate the inner angle, in radians, between two /unit/ vectors.
decimal DegToRad(decimal deg)
Quaternion SphericalToQuaternion(decimal ra, decimal dec, decimal roll)
Return a quaternion that will reorient the coordinate axes so that the x-axis points at the given rig...
Vec3 SphericalToSpatial(decimal ra, decimal de)
Convert from right ascension & declination to a 3d point on the unit sphere.
decimal RadToDeg(decimal rad)
const Mat3 kIdentityMat3
3x3 identity matrix
Quaternion DCMToQuaternion(const Mat3 &dcm)
Convert a rotation matrix (Direction Cosine Matrix) to a quaternion representing the same rotation.
decimal Angle(const Vec3 &vec1, const Vec3 &vec2)
Calculate the inner angle, in radians, between two vectors.
decimal DecimalModulo(decimal x, decimal mod)
Given a decimal, find it "modulo" another decimal, in the true mathematical sense (not remainder).
void SerializeVec3(SerializeContext *ser, const Vec3 &vec)
Serialize a Vec3 to buffer. Takes up space according to SerializeLengthVec3.
Vec3 DeserializeVec3(DeserializeContext *des)
A two dimensional vector with decimaling point components.
decimal MagnitudeSq() const
The square of the magnitude.
Vec2 operator-(const Vec2 &) const
Usual vector subtraction.
decimal operator*(const Vec2 &) const
Vec2 operator+(const Vec2 &) const
Usual vector addition.
decimal Magnitude() const