41 return Vector(v[0][idx], v[1][idx], v[2][idx]);
50 return Vector(v[0][3], v[1][3], v[2][3]);
54 v[0][3] = v[1][3] = v[2][3] = 0._f;
71 transposed(0, 3) = v[0][3];
72 transposed(1, 3) = v[1][3];
73 transposed(2, 3) = v[2][3];
81 return v[0][0] * (v[1][1] * v[2][2] - v[2][1] * v[1][2]) -
82 v[0][1] * (v[1][0] * v[2][2] - v[1][2] * v[2][0]) +
83 v[0][2] * (v[1][0] * v[2][1] - v[1][1] * v[2][0]);
92 inv(0, 0) = v[1][1] * v[2][2] - v[2][1] * v[1][2];
93 inv(1, 0) = -v[1][0] * v[2][2] + v[2][0] * v[1][2];
94 inv(2, 0) = v[1][0] * v[2][1] - v[2][0] * v[1][1];
95 inv(0, 1) = -v[0][1] * v[2][2] + v[2][1] * v[0][2];
96 inv(1, 1) = v[0][0] * v[2][2] - v[2][0] * v[0][2];
97 inv(2, 1) = -v[0][0] * v[2][1] + v[2][0] * v[0][1];
98 inv(0, 2) = v[0][1] * v[1][2] - v[1][1] * v[0][2];
99 inv(1, 2) = -v[0][0] * v[1][2] + v[1][0] * v[0][2];
100 inv(2, 2) = v[0][0] * v[1][1] - v[1][0] * v[0][1];
101 inv(0, 3) = -v[0][1] * v[1][2] * v[2][3] + v[0][1] * v[1][3] * v[2][2] + v[1][1] * v[0][2] * v[2][3] -
102 v[1][1] * v[0][3] * v[2][2] - v[2][1] * v[0][2] * v[1][3] + v[2][1] * v[0][3] * v[1][2];
103 inv(1, 3) = v[0][0] * v[1][2] * v[2][3] - v[0][0] * v[1][3] * v[2][2] - v[1][0] * v[0][2] * v[2][3] +
104 v[1][0] * v[0][3] * v[2][2] + v[2][0] * v[0][2] * v[1][3] - v[2][0] * v[0][3] * v[1][2];
105 inv(2, 3) = -v[0][0] * v[1][1] * v[2][3] + v[0][0] * v[1][3] * v[2][1] + v[1][0] * v[0][1] * v[2][3] -
106 v[1][0] * v[0][3] * v[2][1] - v[2][0] * v[0][1] * v[1][3] + v[2][0] * v[0][3] * v[1][1];
112 for (
Size i = 0; i < 3; ++i) {
113 for (
Size j = 0; j < 3; ++j) {
115 if (!
almostEqual(x, i == j ? 1._f : 0._f, 1.e-6_f)) {
124 return v[0][0] == v[1][1] && v[0][0] == v[2][2] && v[0][1] == 0._f && v[0][2] == 0._f &&
161 const Float u = axis[0];
162 const Float v = axis[1];
163 const Float w = axis[2];
167 Vector(u * u + (v * v + w * w) * c, u * v * (1 - c) - w * s, u * w * (1 - c) + v * s),
168 Vector(u * v * (1 - c) + w * s, v * v + (u * u + w * w) * c, v * w * (1 - c) - u * s),
169 Vector(u * w * (1 - c) - v * s, v * w * (1 - c) + u * s, w * w + (u * u + v * v) * c),
182 return AffineMatrix(v[0] + other.v[0], v[1] + other.v[1], v[2] + other.v[2]);
186 return AffineMatrix(v[0] - other.v[0], v[1] - other.v[1], v[2] - other.v[2]);
192 for (
Size i = 0; i < 3; ++i) {
193 for (
Size j = 0; j < 3; ++j) {
201 for (
Size i = 0; i < 3; ++i) {
202 t[i] =
dot(this->
row(i), rhs) + lhs[i];
209 return Vector(
dot(v[0], u) + v[0][3],
dot(v[1], u) + v[1][3],
dot(v[2], u) + v[2][3]);
257 return v[0] == other.v[0] && v[0][3] == other.v[0][3] &&
258 v[1] == other.v[1] && v[1][3] == other.v[1][3] &&
259 v[2] == other.v[2] && v[2][3] == other.v[2][3];
263 return !(*
this == other);
268 for (
Size i = 0; i < 3; ++i) {
269 for (
Size j = 0; j < 4; ++j) {
270 stream << std::setw(20) << t(i, j);
279 for (
Size i = 0; i < 4; ++i) {
INLINE bool almostEqual(const AffineMatrix &m1, const AffineMatrix &m2, const Float eps=EPS)
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr int PRECISION
Number of valid digits of numbers on output.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Basic vector algebra. Computations are accelerated using SIMD.
INLINE Float getSqrLength(const Vector &v)
BasicVector< Float > Vector
INLINE float dot(const BasicVector< float > &v1, const BasicVector< float > &v2)
Make sure the vector is trivially constructible and destructible, needed for fast initialization of a...
INLINE AffineMatrix & operator*=(const Float value)
INLINE Float determinant() const
Computes determinant of the matrix.
static AffineMatrix identity()
INLINE Vector column(const Size idx) const
INLINE AffineMatrix operator-(const AffineMatrix &other) const
INLINE AffineMatrix operator+(const AffineMatrix &other) const
static AffineMatrix scale(const Vector &scaling)
INLINE Vector translation() const
INLINE AffineMatrix & operator/=(const Float value)
INLINE AffineMatrix & operator-=(const AffineMatrix &other)
INLINE Float & operator()(const Size i, const Size j)
INLINE AffineMatrix & translate(const Vector &t)
INLINE AffineMatrix transpose() const
Returns the transposed matrix.
AffineMatrix(const Vector &v1, const Vector &v2, const Vector &v3)
Construct the matrix from vectors as rows.
static AffineMatrix rotateY(const Float angle)
INLINE AffineMatrix operator*(const AffineMatrix &other) const
Matrix multiplication.
INLINE AffineMatrix & operator+=(const AffineMatrix &other)
INLINE Vector row(const Size idx) const
static AffineMatrix rotateAxis(const Vector &axis, const Float angle)
static AffineMatrix rotateX(const Float angle)
static AffineMatrix rotateZ(const Float angle)
AffineMatrix inverse() const
INLINE AffineMatrix & removeTranslation()
INLINE friend AffineMatrix operator/(const AffineMatrix &t, const Float v)
INLINE Vector operator*(const Vector &u) const
INLINE bool operator==(const AffineMatrix &other) const
INLINE Float operator()(const Size i, const Size j) const
friend std::ostream & operator<<(std::ostream &stream, const AffineMatrix &t)
INLINE friend AffineMatrix operator*(const Float v, const AffineMatrix &t)
INLINE bool operator!=(const AffineMatrix &other) const
bool isOrthogonal() const
static AffineMatrix crossProductOperator(const Vector &a)
INLINE friend AffineMatrix operator*(const AffineMatrix &t, const Float v)