Matrix3.hh
#ifndef RIVET_MATH_MATRIX3
#define RIVET_MATH_MATRIX3
#include "Rivet/Math/MathHeader.hh"
#include "Rivet/Math/MathUtils.hh"
#include "Rivet/Math/MatrixN.hh"
#include "Rivet/Math/Vector3.hh"
namespace Rivet {
class Matrix3 : public Matrix<3> {
public:
Matrix3() { }
Matrix3(const Matrix<3>& m3) : Matrix<3>::Matrix(m3) { }
Matrix3(const Vector3& axis, const double angle) {
const Vector3 normaxis = axis.unit();
_matrix.loadRotation3(angle, normaxis._vec);
}
Matrix3(const Vector3& from, const Vector3& to) {
setAsRotation(from, to);
}
public:
static Matrix3 mkXRotation(const double angle) {
return Matrix3(Vector3(1,0,0), angle);
}
static Matrix3 mkYRotation(const double angle) {
return Matrix3(Vector3(0,1,0), angle);
}
static Matrix3 mkZRotation(const double angle) {
return Matrix3(Vector3(0,0,1), angle);
}
public:
Matrix3& setAsRotation(const Vector3& from, const Vector3& to) {
const double theta = angle(from, to);
if (Rivet::isZero(theta)) {
_matrix.loadIdentity();
} else {
const Vector3 normaxis = cross(from, to).unit();
_matrix.loadRotation3(theta, normaxis._vec);
}
return *this;
}
};
}
#endif
Rivet::theta
double theta(const Vector3 &v)
Synonym for polarAngle.
Definition: Vector3.hh:290
Rivet::Matrix3
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition: Matrix3.hh:13
Rivet::Vector3::unit
Vector3 unit() const
Definition: Vector3.hh:88
Rivet::angle
double angle(const Vector3 &a, const Vector3 &b)
Angle (in radians) between two 3-vectors.
Definition: Vector3.hh:244
Rivet::Matrix
General -dimensional mathematical matrix object.
Definition: MatrixN.hh:14
Rivet::isZero
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.hh:17
Rivet::Vector3
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26