115 assert(result.IsUnit(0.00001));
171 return result >= 0 ? result : result + mod;
175 output <<
"Vec2(x: " << vec.
x <<
", y: " << vec.
y <<
")";
180 output <<
"Vec3(x: " << vec.
x <<
", y: " << vec.
y <<
", z: " << vec.
z <<
")";
212 return x*other.
x +
y*other.
y +
z*other.
z;
217 return {
x*other,
y*other };
222 return {
x*other,
y*other,
z*other };
227 return {
x + other.
x,
y + other.
y };
232 return {
x - other.
x,
y - other.
y };
237 return {
x - other.
x,
y - other.
y,
z - other.
z };
241 return {
x + other.
x,
y + other.
y,
z + other.
z};
247 y*other.
z -
z*other.
y,
248 -(
x*other.
z -
z*other.
x),
249 x*other.
y -
y*other.
x,
256 x*other.
x,
x*other.
y,
x*other.
z,
257 y*other.
x,
y*other.
y,
y*other.
z,
258 z*other.
x,
z*other.
y,
z*other.
z
265 x*other.
At(0,0) +
y*other.
At(0,1) +
z*other.
At(0,2),
266 x*other.
At(1,0) +
y*other.
At(1,1) +
z*other.
At(1,2),
267 x*other.
At(2,0) +
y*other.
At(2,1) +
z*other.
At(2,2),
278 return {
At(0,j),
At(1,j),
At(2,j)};
283 return {
At(i,0),
At(i,1),
At(i,2)};
289 At(0,0)+other.
At(0,0),
At(0,1)+other.
At(0,1),
At(0,2)+other.
At(0,2),
290 At(1,0)+other.
At(1,0),
At(1,1)+other.
At(1,1),
At(1,2)+other.
At(1,2),
291 At(2,0)+other.
At(2,0),
At(2,1)+other.
At(2,1),
At(2,2)+other.
At(2,2)
297#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)
309 vec.
x*
At(0,0) + vec.
y*
At(0,1) + vec.
z*
At(0,2),
310 vec.
x*
At(1,0) + vec.
y*
At(1,1) + vec.
z*
At(1,2),
311 vec.
x*
At(2,0) + vec.
y*
At(2,1) + vec.
z*
At(2,2),
318 s*
At(0,0), s*
At(0,1), s*
At(0,2),
319 s*
At(1,0), s*
At(1,1), s*
At(1,2),
320 s*
At(2,0), s*
At(2,1), s*
At(2,2)
327 At(0,0),
At(1,0),
At(2,0),
328 At(0,1),
At(1,1),
At(2,1),
329 At(0,2),
At(1,2),
At(2,2),
335 return At(0,0) +
At(1,1) +
At(2,2);
340 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)));
349 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),
350 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),
351 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)
363 : type(AttitudeType::QuaternionType), quaternion(quat) {}
366 : type(AttitudeType::DCMType), dcm(matrix) {}
397 bool rotateClockwise = oldYAxis.
CrossProduct(newYAxis) * newXAxis > 0;
406 return xAlign*yAlign;
412 case AttitudeType::QuaternionType:
414 case AttitudeType::DCMType:
424 case AttitudeType::DCMType:
426 case AttitudeType::QuaternionType:
436 case AttitudeType::DCMType:
438 case AttitudeType::QuaternionType:
439 return quaternion.Rotate(vec);
448 case AttitudeType::DCMType:
450 case AttitudeType::QuaternionType:
451 return quaternion.ToSpherical();
459 case AttitudeType::DCMType:
460 case AttitudeType::QuaternionType:
#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 operator+(const Vec3 &) const
Vec3 CrossProduct(const Vec3 &) const
Usual vector cross product.
decimal Magnitude() const
Vec3 operator-(const Vec3 &) const
Usual vector subtraction.
#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.
T DeserializePrimitive(DeserializeContext *des)
decimal DecimalModulo(decimal x, decimal mod)
Given a decimal, find it "modulo" another decimal, in the true mathematical sense (not remainder).
void SerializePrimitive(SerializeContext *ser, const T &val)
void SerializeVec3(SerializeContext *ser, const Vec3 &vec)
Serialize a Vec3 to buffer. Takes up space according to SerializeLengthVec3.
Vec3 DeserializeVec3(DeserializeContext *des)
std::ostream & operator<<(std::ostream &output, const Vec2 &vec)
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