8#ifndef META_OCEAN_MATH_SQUARE_MATRIX_3_H
9#define META_OCEAN_MATH_SQUARE_MATRIX_3_H
25template <
typename T>
class EulerT;
27template <
typename T>
class HomogenousMatrixT4;
29template <
typename T>
class QuaternionT;
31template <
typename T>
class RotationT;
33template <
typename T>
class SquareMatrixT4;
36template <
typename T>
class SquareMatrixT3;
118 template <
typename U>
164 template <
typename U>
179 template <
typename U>
213 explicit SquareMatrixT3(
const T& m00,
const T& m10,
const T& m20,
const T& m01,
const T& m11,
const T& m21,
const T& m02,
const T& m12,
const T& m22);
433 template <
typename U>
434 void copyElements(U* arrayValues,
const bool valuesRowAligned =
false)
const;
441 void copyElements(T* arrayValues,
const bool valuesRowAligned =
false)
const;
602 inline T
operator()(
const unsigned int row,
const unsigned int column)
const;
611 inline T&
operator()(
const unsigned int row,
const unsigned int column);
680 template <
typename U>
690 template <
typename U>
709 values_[0] = T(matrix.
values_[0]);
710 values_[1] = T(matrix.
values_[1]);
711 values_[2] = T(matrix.
values_[2]);
712 values_[3] = T(matrix.
values_[3]);
713 values_[4] = T(matrix.
values_[4]);
714 values_[5] = T(matrix.
values_[5]);
715 values_[6] = T(matrix.
values_[6]);
716 values_[7] = T(matrix.
values_[7]);
717 values_[8] = T(matrix.
values_[8]);
789 values_[0] = cy * cz + sx * sy * sz;
790 values_[1] = cx * sz;
791 values_[2] = -cz * sy + cy * sx * sz;
792 values_[3] = cz * sx * sy - cy * sz;
793 values_[4] = cx * cz;
794 values_[5] = cy * cz * sx + sy * sz;
795 values_[6] = cx * sy;
797 values_[8] = cx * cy;
807 ocean_assert(rotation.
isValid());
810 const T cosValue1 = T(1.0) - cosValue;
815 const T xx = axis.
x() * axis.
x() * cosValue1;
816 const T yy = axis.
y() * axis.
y() * cosValue1;
817 const T zz = axis.
z() * axis.
z() * cosValue1;
818 const T xy = axis.
x() * axis.
y() * cosValue1;
819 const T xz = axis.
x() * axis.
z() * cosValue1;
820 const T yz = axis.
y() * axis.
z() * cosValue1;
822 const T nx = axis.
x() * sinValue;
823 const T ny = axis.
y() * sinValue;
824 const T nz = axis.
z() * sinValue;
826 values_[0] = xx + cosValue;
827 values_[1] = xy + nz;
828 values_[2] = xz - ny;
830 values_[3] = xy - nz;
831 values_[4] = yy + cosValue;
832 values_[5] = yz + nx;
834 values_[6] = xz + ny;
835 values_[7] = yz - nx;
836 values_[8] = zz + cosValue;
844 ocean_assert(quaternion.
isValid());
846 const T xx = quaternion.
x() * quaternion.
x();
847 const T yy = quaternion.
y() * quaternion.
y();
848 const T zz = quaternion.
z() * quaternion.
z();
850 const T wx = quaternion.
w() * quaternion.
x();
851 const T wy = quaternion.
w() * quaternion.
y();
852 const T wz = quaternion.
w() * quaternion.
z();
853 const T xy = quaternion.
x() * quaternion.
y();
854 const T xz = quaternion.
x() * quaternion.
z();
855 const T yz = quaternion.
y() * quaternion.
z();
857 values_[0] = T(1.0) - T(2.0) * (yy + zz);
858 values_[1] = T(2.0) * (wz + xy);
859 values_[2] = T(2.0) * (xz - wy);
861 values_[3] = T(2.0) * (xy - wz);
862 values_[4] = T(1.0) - T(2.0) * (xx + zz);
863 values_[5] = T(2.0) * (wx + yz);
865 values_[6] = T(2.0) * (wy + xz);
866 values_[7] = T(2.0) * (yz - wx);
867 values_[8] = T(1.0) - T(2.0) * (xx + yy);
891 memcpy(values_, xAxis(),
sizeof(T) * 3);
892 memcpy(values_ + 3, yAxis(),
sizeof(T) * 3);
893 memcpy(values_ + 6, zAxis(),
sizeof(T) * 3);
899 values_[0] = diagonal[0];
903 values_[4] = diagonal[1];
907 values_[8] = diagonal[2];
914 ocean_assert(arrayValues);
916 for (
unsigned int n = 0u; n < 9u; ++n)
918 values_[n] = T(arrayValues[n]);
925 ocean_assert(arrayValues);
926 memcpy(values_, arrayValues,
sizeof(T) * 9);
933 ocean_assert(arrayValues);
935 if (valuesRowAligned)
937 values_[0] = T(arrayValues[0]);
938 values_[1] = T(arrayValues[3]);
939 values_[2] = T(arrayValues[6]);
940 values_[3] = T(arrayValues[1]);
941 values_[4] = T(arrayValues[4]);
942 values_[5] = T(arrayValues[7]);
943 values_[6] = T(arrayValues[2]);
944 values_[7] = T(arrayValues[5]);
945 values_[8] = T(arrayValues[8]);
950 for (
unsigned int n = 0u; n < 9u; ++n)
952 values_[n] = T(arrayValues[n]);
960 ocean_assert(arrayValues);
962 if (valuesRowAligned)
964 values_[0] = arrayValues[0];
965 values_[1] = arrayValues[3];
966 values_[2] = arrayValues[6];
967 values_[3] = arrayValues[1];
968 values_[4] = arrayValues[4];
969 values_[5] = arrayValues[7];
970 values_[6] = arrayValues[2];
971 values_[7] = arrayValues[5];
972 values_[8] = arrayValues[8];
976 memcpy(values_, arrayValues,
sizeof(T) * 9);
983 memcpy(values_, transformation(),
sizeof(T) * 3);
984 memcpy(values_ + 3, transformation() + 4,
sizeof(T) * 3);
985 memcpy(values_ + 6, transformation() + 8,
sizeof(T) * 3);
991 memcpy(values_, transformation(),
sizeof(T) * 3);
992 memcpy(values_ + 3, transformation() + 4,
sizeof(T) * 3);
993 memcpy(values_ + 6, transformation() + 8,
sizeof(T) * 3);
1014 const T d = determinant();
1018 const T d0 = b[0] * (values_[4] * values_[8] - values_[5] * values_[7]) + b[1] * (values_[5] * values_[6] - values_[3] * values_[8]) + b[2] * (values_[3] * values_[7] - values_[4] * values_[6]);
1019 const T d1 = values_[0] * ( b[1] * values_[8] - b[2] * values_[7]) + values_[1] * ( b[2] * values_[6] - b[0] * values_[8]) + values_[2] * ( b[0] * values_[7] - b[1] * values_[6]);
1020 const T d2 = values_[0] * (values_[4] * b[2] - values_[5] * b[1]) + values_[1] * (values_[5] * b[0] - values_[3] * b[2]) + values_[2] * (values_[3] * b[1] - values_[4] * b[0]);
1022 const T invD = T(1) / d;
1043 return (values_[0] + values_[1] + values_[2] + values_[3] + values_[4] + values_[5] + values_[6] + values_[7] + values_[8]);
1046template <
typename T>
1052template <
typename T>
1058template <
typename T>
1061 return !(*
this == matrix);
1064template <
typename T>
1067 *
this = *
this * matrix;
1071template <
typename T>
1074 ocean_assert(index < 9u);
1075 return values_[index];
1078template <
typename T>
1081 ocean_assert(index < 9u);
1082 return values_[index];
1085template <
typename T>
1088 ocean_assert(row < 3u && column < 3u);
1089 return values_[column * 3 + row];
1092template <
typename T>
1095 ocean_assert(row < 3u && column < 3u);
1096 return values_[column * 3 + row];
1099template <
typename T>
1102 ocean_assert(index < 9u);
1103 return values_[index];
1106template <
typename T>
1109 ocean_assert(index < 9u);
1110 return values_[index];
1113template <
typename T>
1119template <
typename T>
1125template <
typename T>
1128 size_t seed = std::hash<T>{}(matrix.
values_[0]);
1130 for (
unsigned int n = 1u; n < 9u; ++n)
1132 seed ^= std::hash<T>{}(matrix.
values_[n]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1138template <
typename T>
1144template <
typename T>
1149 result.
values_[1] = values_[3];
1150 result.
values_[3] = values_[1];
1152 result.
values_[2] = values_[6];
1153 result.
values_[6] = values_[2];
1155 result.
values_[5] = values_[7];
1156 result.
values_[7] = values_[5];
1161template <
typename T>
1176template <
typename T>
1181 if (!invert(invertedMatrix))
1183 ocean_assert(
false &&
"Could not invert the matrix.");
1187 return invertedMatrix;
1190template <
typename T>
1195 if (!invert(invertedMatrix))
1200 *
this = invertedMatrix;
1205template <
typename T>
1209 const T v48 = values_[4] * values_[8];
1210 const T v57 = values_[5] * values_[7];
1211 const T v56 = values_[5] * values_[6];
1212 const T v38 = values_[3] * values_[8];
1213 const T v37 = values_[3] * values_[7];
1214 const T v46 = values_[4] * values_[6];
1216 const T v48_57 = v48 - v57;
1217 const T v56_38 = v56 - v38;
1218 const T v37_46 = v37 - v46;
1220 const T det = values_[0] * v48_57 + values_[1] * v56_38 + values_[2] * v37_46;
1227 const T factor = T(1.0) / det;
1229 invertedMatrix.
values_[0] = (v48_57) * factor;
1230 invertedMatrix.
values_[1] = (values_[2] * values_[7] - values_[1] * values_[8]) * factor;
1231 invertedMatrix.
values_[2] = (values_[1] * values_[5] - values_[2] * values_[4]) * factor;
1233 invertedMatrix.
values_[3] = (v56_38) * factor;
1234 invertedMatrix.
values_[4] = (values_[0] * values_[8] - values_[2] * values_[6]) * factor;
1235 invertedMatrix.
values_[5] = (values_[2] * values_[3] - values_[0] * values_[5]) * factor;
1237 invertedMatrix.
values_[6] = (v37_46) * factor;
1238 invertedMatrix.
values_[7] = (values_[1] * values_[6] - values_[0] * values_[7]) * factor;
1239 invertedMatrix.
values_[8] = (values_[0] * values_[4] - values_[1] * values_[3]) * factor;
1241#ifdef OCEAN_INTENSIVE_DEBUG
1242 if (!std::is_same<T, float>::value)
1248 for (
unsigned int n = 0; n < 9u; ++n)
1257 T absoluteAverageEnergy = 0;
1258 for (
unsigned int n = 0u; n < 9u; ++n)
1263 absoluteAverageEnergy *= T(0.111111111111111111);
1267 if (absoluteAverageEnergy <= 1)
1269 ocean_assert_accuracy(!
"This should never happen!");
1273 const T adjustedDistance = distance / absoluteAverageEnergy;
1283template <
typename T>
1286 return values_[0] * (values_[4] * values_[8] - values_[5] * values_[7])
1287 + values_[1] * (values_[5] * values_[6] - values_[3] * values_[8])
1288 + values_[2] * (values_[3] * values_[7] - values_[4] * values_[6]);
1291template <
typename T>
1294 return values_[0] + values_[4] + values_[8];
1297template <
typename T>
1300 values_[0] = T(1.0);
1301 values_[1] = T(0.0);
1302 values_[2] = T(0.0);
1303 values_[3] = T(0.0);
1304 values_[4] = T(1.0);
1305 values_[5] = T(0.0);
1306 values_[6] = T(0.0);
1307 values_[7] = T(0.0);
1308 values_[8] = T(1.0);
1311template <
typename T>
1314 values_[0] = T(0.0);
1315 values_[1] = T(0.0);
1316 values_[2] = T(0.0);
1317 values_[3] = T(0.0);
1318 values_[4] = T(0.0);
1319 values_[5] = T(0.0);
1320 values_[6] = T(0.0);
1321 values_[7] = T(0.0);
1322 values_[8] = T(0.0);
1325template <
typename T>
1333template <
typename T>
1341template <
typename T>
1347template <
typename T>
1353template <
typename T>
1359template <
typename T>
1365template <
typename T>
1368 ocean_assert(epsilon >= 0);
1378template <
typename T>
1381 ocean_assert(epsilon >= T(0));
1386template <
typename T>
1396template <
typename T>
1402template <
typename T>
1408template <
typename T>
1414template <
typename T>
1417 ocean_assert(!isSingular());
1424 const T xScale = xAxis.
length();
1429 const T xyShear = xAxis * yAxis;
1432 yAxis -= xAxis * xyShear;
1435 const T yScale = yAxis.
length();
1440 const T xzShear = xAxis * zAxis;
1442 zAxis -= xAxis * xzShear;
1445 const T yzShear = yAxis * zAxis;
1447 zAxis -= yAxis * yzShear;
1450 const T zScale = zAxis.
length();
1454#ifdef OCEAN_INTENSIVE_DEBUG
1455 if (std::is_same<T, double>::value)
1467template <
typename T>
1470 ocean_assert(eigenValues);
1494 const T a = values_[0];
1495 const T d = values_[1];
1496 const T g = values_[2];
1498 const T b = values_[3];
1499 const T e = values_[4];
1500 const T h = values_[5];
1502 const T c = values_[6];
1503 const T f = values_[7];
1504 const T i = values_[8];
1506 const T a1 = T(1.0);
1507 const T a2 = -(a + e + i);
1508 const T a3 = -(-a * e - a * i - e * i + g * c + h * f + d * b);
1509 const T a4 = -a * e * i - b * f * g - c * d * h + g * e * c + h * f * a + d * i * b;
1520template <
typename T>
1523 ocean_assert(eigenValues !=
nullptr && eigenVectors !=
nullptr);
1546 const T a = values_[0];
1547 const T d = values_[1];
1548 const T g = values_[2];
1550 const T b = values_[3];
1551 const T e = values_[4];
1552 const T h = values_[5];
1554 const T c = values_[6];
1555 const T f = values_[7];
1556 const T i = values_[8];
1558 const T a1 = T(1.0);
1559 const T a2 = -(a + e + i);
1560 const T a3 = -(-a * e - a * i - e * i + g * c + h * f + d * b);
1561 const T a4 = -a * e * i - b * f * g - c * d * h + g * e * c + h * f * a + d * i * b;
1579 for (
unsigned int n = 0u; n < 3u; ++n)
1589 T sqrCandidate0(candidate0.
sqr());
1590 T sqrCandidate1(candidate1.
sqr());
1591 T sqrCandidate2(candidate2.
sqr());
1604 sqrCandidate0 = candidate0.
sqr();
1605 sqrCandidate1 = candidate1.
sqr();
1606 sqrCandidate2 = candidate2.
sqr();
1615 eigenVectors[n] = candidate0;
1624template <
typename T>
1627 return VectorT3<T>(values_[0], values_[4], values_[8]);
1630template <
typename T>
1631template <
typename U>
1634 ocean_assert(arrayValues !=
nullptr);
1636 if (valuesRowAligned)
1641 arrayValues[0] = U(values_[0]);
1642 arrayValues[1] = U(values_[3]);
1643 arrayValues[2] = U(values_[6]);
1645 arrayValues[3] = U(values_[1]);
1646 arrayValues[4] = U(values_[4]);
1647 arrayValues[5] = U(values_[7]);
1649 arrayValues[6] = U(values_[2]);
1650 arrayValues[7] = U(values_[5]);
1651 arrayValues[8] = U(values_[8]);
1658 arrayValues[0] = U(values_[0]);
1659 arrayValues[1] = U(values_[1]);
1660 arrayValues[2] = U(values_[2]);
1661 arrayValues[3] = U(values_[3]);
1662 arrayValues[4] = U(values_[4]);
1663 arrayValues[5] = U(values_[5]);
1664 arrayValues[6] = U(values_[6]);
1665 arrayValues[7] = U(values_[7]);
1666 arrayValues[8] = U(values_[8]);
1670template <
typename T>
1673 ocean_assert(arrayValues !=
nullptr);
1675 if (valuesRowAligned)
1680 arrayValues[0] = values_[0];
1681 arrayValues[1] = values_[3];
1682 arrayValues[2] = values_[6];
1684 arrayValues[3] = values_[1];
1685 arrayValues[4] = values_[4];
1686 arrayValues[5] = values_[7];
1688 arrayValues[6] = values_[2];
1689 arrayValues[7] = values_[5];
1690 arrayValues[8] = values_[8];
1697 memcpy(arrayValues, values_,
sizeof(T) * 9);
1701template <
typename T>
1704 return SquareMatrixT3<T>(0, vector(2), -vector(1), -vector(2), 0, vector(0), vector(1), -vector(0), 0);
1707template <
typename T>
1716 const T z = values_[2] * vector[0] + values_[5] * vector[1] + values_[8];
1720 const T factor = T(1) / z;
1722 result =
VectorT2<T>((values_[0] * vector[0] + values_[3] * vector[1] + values_[6]) * factor,
1723 (values_[1] * vector[0] + values_[4] * vector[1] + values_[7]) * factor);
1731template <
typename T>
1746#ifdef OCEAN_INTENSIVE_DEBUG
1748 ocean_assert(debugMatrix == result);
1754template <
typename T>
1757 return isEqual(matrix);
1760template <
typename T>
1778template <
typename T>
1781 values_[0] += matrix.
values_[0];
1782 values_[1] += matrix.
values_[1];
1783 values_[2] += matrix.
values_[2];
1784 values_[3] += matrix.
values_[3];
1785 values_[4] += matrix.
values_[4];
1786 values_[5] += matrix.
values_[5];
1787 values_[6] += matrix.
values_[6];
1788 values_[7] += matrix.
values_[7];
1789 values_[8] += matrix.
values_[8];
1794template <
typename T>
1812template <
typename T>
1815 values_[0] -= matrix.
values_[0];
1816 values_[1] -= matrix.
values_[1];
1817 values_[2] -= matrix.
values_[2];
1818 values_[3] -= matrix.
values_[3];
1819 values_[4] -= matrix.
values_[4];
1820 values_[5] -= matrix.
values_[5];
1821 values_[6] -= matrix.
values_[6];
1822 values_[7] -= matrix.
values_[7];
1823 values_[8] -= matrix.
values_[8];
1828template <
typename T>
1833 result.
values_[0] = -values_[0];
1834 result.
values_[1] = -values_[1];
1835 result.
values_[2] = -values_[2];
1836 result.
values_[3] = -values_[3];
1837 result.
values_[4] = -values_[4];
1838 result.
values_[5] = -values_[5];
1839 result.
values_[6] = -values_[6];
1840 result.
values_[7] = -values_[7];
1841 result.
values_[8] = -values_[8];
1846template <
typename T>
1864template <
typename T>
1873 const T z = values_[2] * vector[0] + values_[5] * vector[1] + values_[8];
1876 const T factor = T(1) / z;
1878 return VectorT2<T>((values_[0] * vector[0] + values_[3] * vector[1] + values_[6]) * factor,
1879 (values_[1] * vector[0] + values_[4] * vector[1] + values_[7]) * factor);
1882template <
typename T>
1885 return VectorT3<T>(values_[0] * vector[0] + values_[3] * vector[1] + values_[6] * vector[2],
1886 values_[1] * vector[0] + values_[4] * vector[1] + values_[7] * vector[2],
1887 values_[2] * vector[0] + values_[5] * vector[1] + values_[8] * vector[2]);
1890#if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 20
1914 const double*
const vectorValues = vector.
data();
1917 const __m128d v0 = _mm_load1_pd(vectorValues + 0);
1919 const __m128d c0 = _mm_loadu_pd(values_ + 0);
1922 const __m128d r0 = _mm_mul_pd(c0, v0);
1926 const __m128d v1 = _mm_load1_pd(vectorValues + 1);
1927 const __m128d c1 = _mm_loadu_pd(values_ + 3);
1928 const __m128d r1 = _mm_mul_pd(c1, v1);
1931 __m128d result_f64x2 = _mm_add_pd(r0, r1);
1935 const __m128d v2 = _mm_load1_pd(vectorValues + 2);
1936 const __m128d c2 = _mm_loadu_pd(values_ + 6);
1937 const __m128d r2 = _mm_mul_pd(c2, v2);
1940 result_f64x2 = _mm_add_pd(result_f64x2, r2);
1943 result[2] = values_[2] * vector[0] + values_[5] * vector[1] + values_[8] * vector[2];
1944 _mm_storeu_pd(result.
data(), result_f64x2);
1978 const __m128 v0 = _mm_load1_ps(vector.
data() + 0);
1981 const __m128 c0 = _mm_loadu_ps(values_ + 0);
1984 const __m128 r0 = _mm_mul_ps(c0, v0);
1988 const __m128 v1 = _mm_load1_ps(vector.
data() + 1);
1989 const __m128 c1 = _mm_loadu_ps(values_ + 3);
1990 const __m128 r1 = _mm_mul_ps(c1, v1);
1993 __m128 result_f32x4 = _mm_add_ps(r0, r1);
1997 const __m128 v2 = _mm_load1_ps(vector.
data() + 2);
1998 __m128 c2 = _mm_loadu_ps(values_ + 5);
1999 c2 = _mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(c2), 4));
2000 const __m128 r2 = _mm_mul_ps(c2, v2);
2003 result_f32x4 = _mm_add_ps(result_f32x4, r2);
2005 float resultValues[4];
2006 _mm_storeu_ps(resultValues, result_f32x4);
2014template <
typename T>
2031template <
typename T>
2034 values_[0] *= value;
2035 values_[1] *= value;
2036 values_[2] *= value;
2037 values_[3] *= value;
2038 values_[4] *= value;
2039 values_[5] *= value;
2040 values_[6] *= value;
2041 values_[7] *= value;
2042 values_[8] *= value;
2047template <
typename T>
2050 ocean_assert((vectors && results) || number == 0);
2052 for (
size_t n = 0; n < number; ++n)
2054 results[n] = matrix * vectors[n];
2058template <
typename T>
2061 ocean_assert((vectors && results) || number == 0);
2063 for (
size_t n = 0; n < number; ++n)
2065 results[n] = matrix * vectors[n];
2069#if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 20
2089 const __m128 c0 = _mm_loadu_ps(matrix.
values_ + 0);
2090 const __m128 c1 = _mm_loadu_ps(matrix.
values_ + 3);
2091 __m128 c2 = _mm_loadu_ps(matrix.
values_ + 5);
2092 c2 = _mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(c2), 4));
2094 for (
size_t n = 0u; n < number - 1; ++n)
2096 const __m128 v0 = _mm_load1_ps(vectors[n].data() + 0);
2097 const __m128 v1 = _mm_load1_ps(vectors[n].data() + 1);
2098 const __m128 v2 = _mm_load1_ps(vectors[n].data() + 2);
2100 const __m128 r0 = _mm_mul_ps(c0, v0);
2101 const __m128 r1 = _mm_mul_ps(c1, v1);
2103 __m128 result_f32x4= _mm_add_ps(r0, r1);
2105 const __m128 r2 = _mm_mul_ps(c2, v2);
2107 result_f32x4 = _mm_add_ps(result_f32x4, r2);
2110 _mm_storeu_ps(results[n].data(), result_f32x4);
2115 const __m128 v0 = _mm_load1_ps(vectors[number - 1].data() + 0);
2116 const __m128 v1 = _mm_load1_ps(vectors[number - 1].data() + 1);
2117 const __m128 v2 = _mm_load1_ps(vectors[number - 1].data() + 2);
2119 const __m128 r0 = _mm_mul_ps(c0, v0);
2120 const __m128 r1 = _mm_mul_ps(c1, v1);
2122 __m128 result_f32x4 = _mm_add_ps(r0, r1);
2124 const __m128 r2 = _mm_mul_ps(c2, v2);
2126 result_f32x4 = _mm_add_ps(result_f32x4, r2);
2128 float resultValues[4];
2129 _mm_storeu_ps(resultValues, result_f32x4);
2136template <
typename T>
2137template <
typename U>
2141 result.reserve(matrices.size());
2145 result.emplace_back(matrix);
2165template <
typename T>
2166template <
typename U>
2169 std::vector< SquareMatrixT3<T> > result;
2170 result.reserve(size);
2172 for (
size_t n = 0; n < size; ++n)
2174 result.emplace_back(matrices[n]);
2180template <
typename T>
2183 stream <<
"|" << matrix(0, 0) <<
", " << matrix(0, 1) <<
", " << matrix(0, 2) <<
"|" << std::endl;
2184 stream <<
"|" << matrix(1, 0) <<
", " << matrix(1, 1) <<
", " << matrix(1, 2) <<
"|" << std::endl;
2185 stream <<
"|" << matrix(2, 0) <<
", " << matrix(2, 1) <<
", " << matrix(2, 2) <<
"|";
2190template <
bool tActive,
typename T>
2191MessageObject<tActive>&
operator<<(MessageObject<tActive>& messageObject,
const SquareMatrixT3<T>& matrix)
2193 return messageObject <<
"|" << matrix(0, 0) <<
", " << matrix(0, 1) <<
", " << matrix(0, 2) <<
"|\n|"
2194 << matrix(1, 0) <<
", " << matrix(1, 1) <<
", " << matrix(1, 2) <<
"|\n|"
2195 << matrix(2, 0) <<
", " << matrix(2, 1) <<
", " << matrix(2, 2) <<
"|";
2198template <
bool tActive,
typename T>
2199MessageObject<tActive>&
operator<<(MessageObject<tActive>&& messageObject,
const SquareMatrixT3<T>& matrix)
2201 return messageObject <<
"|" << matrix(0, 0) <<
", " << matrix(0, 1) <<
", " << matrix(0, 2) <<
"|\n|"
2202 << matrix(1, 0) <<
", " << matrix(1, 1) <<
", " << matrix(1, 2) <<
"|\n|"
2203 << matrix(2, 0) <<
", " << matrix(2, 1) <<
", " << matrix(2, 2) <<
"|";
This class provides several functions to solve equations with different degree using floating point v...
Definition Equation.h:53
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition Euler.h:80
const T & yaw() const
Returns the yaw angle.
Definition Euler.h:315
const T & roll() const
Returns the roll angle.
Definition Euler.h:339
const T & pitch() const
Returns the pitch angle.
Definition Euler.h:327
This class implements a 4x4 homogeneous transformation matrix using floating point values with the pr...
Definition HomogenousMatrix4.h:110
This class provides basic numeric functionalities.
Definition Numeric.h:57
static T sin(const T value)
Returns the sine of a given value.
Definition Numeric.h:1568
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static T sqrt(const T value)
Returns the square root of a given value.
Definition Numeric.h:1533
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2389
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition Numeric.h:1495
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2090
static T cos(const T value)
Returns the cosine of a given value.
Definition Numeric.h:1584
static constexpr bool isNotEqualEps(const T value)
Returns whether a value is not smaller than or equal to a small epsilon.
Definition Numeric.h:2240
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
const T & x() const
Returns the x value of the quaternion.
Definition Quaternion.h:919
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition Quaternion.h:901
const T & w() const
Returns the w value of the quaternion.
Definition Quaternion.h:907
const T & y() const
Returns the y value of the quaternion.
Definition Quaternion.h:931
const T & z() const
Returns the z value of the quaternion.
Definition Quaternion.h:943
This class implements a axis-angle rotation using floating point values.
Definition Rotation.h:79
VectorT3< T > axis() const
Returns the axis of the rotation.
Definition Rotation.h:748
T angle() const
Returns the angle of the rotation.
Definition Rotation.h:754
bool isValid() const
Returns whether this rotation has valid parameters.
Definition Rotation.h:673
size_t operator()(const SquareMatrixT3< T > &matrix) const
Hash function.
Definition SquareMatrix3.h:1126
VectorT3< T > xAxis() const
Returns the x axis which is the first column of the matrix.
Definition SquareMatrix3.h:1397
bool eigenValues(T *eigenValues) const
Determines the eigen values of this matrix.
Definition SquareMatrix3.h:1468
T * operator()()
Access operator.
Definition SquareMatrix3.h:1120
SquareMatrixT3< T > orthonormalMatrix() const
Returns the orthonormal matrix of this matrix by scaling the x-axis and adjusting y- and z-axis.
Definition SquareMatrix3.h:1415
SquareMatrixT3(const SquareMatrixT3< U > &matrix)
Copy constructor for a matrix with difference element data type than T.
Definition SquareMatrix3.h:707
OCEAN_FORCE_INLINE VectorT2< T > operator*(const VectorT2< T > &vector) const
Multiply operator for a 2D vector.
Definition SquareMatrix3.h:1865
static SquareMatrixT3< T > skewSymmetricMatrix(const VectorT3< T > &vector)
Creates a skew symmetric 3x3 matrix for a specific vector.
Definition SquareMatrix3.h:1702
T operator[](const unsigned int index) const
Element operator.
Definition SquareMatrix3.h:1072
SquareMatrixT3(const U *arrayValues)
Creates a new SquareMatrixT3 object by nine elements of float type U.
Definition SquareMatrix3.h:912
bool eigenSystem(T *eigenValues, VectorT3< T > *eigenVectors) const
Performs an eigen value analysis.
Definition SquareMatrix3.h:1521
bool isEqual(const SquareMatrixT3< T > &matrix, const T eps=NumericT< T >::eps()) const
Returns whether two matrices are almost identical up to a specified epsilon.
Definition SquareMatrix3.h:1387
bool invert()
Inverts this matrix in place.
Definition SquareMatrix3.h:1191
T & operator()(const unsigned int index)
Element operator.
Definition SquareMatrix3.h:1107
bool isNull() const
Returns whether this matrix is a zero matrix.
Definition SquareMatrix3.h:1334
static size_t elements()
Returns the number of elements this matrix has.
Definition SquareMatrix3.h:1139
SquareMatrixT3()
Creates a new SquareMatrixT3 object with undefined elements.
Definition SquareMatrix3.h:700
bool isAffine() const
Returns true if this matrix is a affine transformation.
Definition SquareMatrix3.h:1354
SquareMatrixT3< T > operator+(const SquareMatrixT3< T > &matrix) const
Adds two matrices.
Definition SquareMatrix3.h:1761
SquareMatrixT3(const VectorT3< T > &xAxis, const VectorT3< T > &yAxis, const VectorT3< T > &zAxis)
Creates a new SquareMatrixT3 object by three axes.
Definition SquareMatrix3.h:889
T values_[9]
The nine values of the matrix.
Definition SquareMatrix3.h:696
SquareMatrixT3(const U *arrayValues, const bool valuesRowAligned)
Creates a new SquareMatrixT3 object by nine elements.
Definition SquareMatrix3.h:931
SquareMatrixT3< T > transposedMultiply(const SquareMatrixT3< T > &right) const
Multiplies this transposed matrix with a second matrix.
Definition SquareMatrix3.h:1732
T Type
Definition of the used data type.
Definition SquareMatrix3.h:97
SquareMatrixT3(const T *arrayValues, const bool valuesRowAligned)
Creates a new SquareMatrixT3 object by nine elements.
Definition SquareMatrix3.h:958
void transpose()
Transposes the matrix.
Definition SquareMatrix3.h:1162
SquareMatrixT3< T > & operator=(const SquareMatrixT3< T > &)=default
Default copy assignment operator.
OCEAN_FORCE_INLINE SquareMatrixT3< T > operator*(const T value) const
Multiplies this matrix with a scalar value.
Definition SquareMatrix3.h:2015
OCEAN_FORCE_INLINE VectorT3< T > operator*(const VectorT3< T > &vector) const
Multiply operator for a 3D vector.
Definition SquareMatrix3.h:1883
SquareMatrixT3< T > transposed() const
Returns the transposed of this matrix.
Definition SquareMatrix3.h:1145
static SquareMatricesT3< T > matrices2matrices(const SquareMatricesT3< U > &matrices)
Converts matrices with specific data type to matrices with different data type.
Definition SquareMatrix3.h:2138
void copyElements(U *arrayValues, const bool valuesRowAligned=false) const
Copies the elements of this matrix to an array with floating point values of type U.
Definition SquareMatrix3.h:1632
bool multiply(const VectorT2< T > &vector, VectorT2< T > &result) const
Multiplies a 2D vector with this matrix (from the right).
Definition SquareMatrix3.h:1708
SquareMatrixT3(const SquareMatrixT3< T > &matrix)=default
Copy constructor.
T absSum() const
Calculates the sum of absolute value of elements.
Definition SquareMatrix3.h:1035
T & operator[](const unsigned int index)
Element operator.
Definition SquareMatrix3.h:1079
SquareMatrixT3< T > operator-() const
Returns the negative matrix of this matrix (all matrix elements are multiplied by -1).
Definition SquareMatrix3.h:1829
friend class SquareMatrixT3
Definition SquareMatrix3.h:90
OCEAN_FORCE_INLINE SquareMatrixT3< T > operator*(const SquareMatrixT3< T > &matrix) const
Multiplies two matrices.
Definition SquareMatrix3.h:1847
SquareMatrixT3< T > & operator-=(const SquareMatrixT3< T > &matrix)
Subtracts and assigns two matrices.
Definition SquareMatrix3.h:1813
static void multiply(const SquareMatrixT3< T > &matrix, const VectorT3< T > *vectors, VectorT3< T > *results, const size_t number)
Multiplies several 3D vectors with a given 3x3 matrix.
Definition SquareMatrix3.h:2059
bool operator!=(const SquareMatrixT3< T > &matrix) const
Returns whether two matrices are not identical up to a small epsilon.
Definition SquareMatrix3.h:1059
static void multiply(const SquareMatrixT3< T > &matrix, const VectorT2< T > *vectors, VectorT2< T > *results, const size_t number)
Multiplies several 2D vectors with a given 3x3 matrix.
Definition SquareMatrix3.h:2048
SquareMatrixT3(const bool setToIdentity)
Creates a new SquareMatrixT3 object.
Definition SquareMatrix3.h:721
SquareMatrixT3(const EulerT< T > &euler)
Creates a new SquareMatrixT3 rotation matrix by a given Euler rotation.
Definition SquareMatrix3.h:750
SquareMatrixT3(const HomogenousMatrixT4< T > &transformation)
Creates a 3x3 rotation matrix by a given 4x4 homogeneous transformation.
Definition SquareMatrix3.h:981
VectorT3< T > zAxis() const
Returns the z axis which is the last column of the matrix.
Definition SquareMatrix3.h:1409
SquareMatrixT3(const RotationT< T > &rotation)
Creates a new 3x3 matrix object by a given angle-axis rotation.
Definition SquareMatrix3.h:803
void toNull()
Sets the matrix to a zero matrix.
Definition SquareMatrix3.h:1312
const T * data() const
Returns a pointer to the internal values.
Definition SquareMatrix3.h:1047
T * data()
Returns a pointer to the internal values.
Definition SquareMatrix3.h:1053
const T * operator()() const
Access operator.
Definition SquareMatrix3.h:1114
void copyElements(T *arrayValues, const bool valuesRowAligned=false) const
Copies the elements of this matrix to an array with floating point values of type T.
Definition SquareMatrix3.h:1671
bool isHomography() const
Returns true if this matrix is perspective transform/homography.
Definition SquareMatrix3.h:1360
bool isSimilarity() const
Returns true if this matrix is a similarity transformation.
Definition SquareMatrix3.h:1348
VectorT3< T > yAxis() const
Returns the y axis which is the middle column of the matrix.
Definition SquareMatrix3.h:1403
void toIdentity()
Sets the matrix to the identity matrix.
Definition SquareMatrix3.h:1298
bool solve(const VectorT3< T > &b, VectorT3< T > &x) const
Solve a simple 3x3 system of linear equations: Ax = b Beware: The system of linear equations is assum...
Definition SquareMatrix3.h:997
SquareMatrixT3(const T &m00, const T &m10, const T &m20, const T &m01, const T &m11, const T &m21, const T &m02, const T &m12, const T &m22)
Creates a 3x3 rotation matrix by 9 given matrix elements.
Definition SquareMatrix3.h:873
T operator()(const unsigned int index) const
Element operator.
Definition SquareMatrix3.h:1100
T determinant() const
Returns the determinant of the matrix.
Definition SquareMatrix3.h:1284
SquareMatrixT3< T > operator-(const SquareMatrixT3< T > &matrix) const
Subtracts two matrices.
Definition SquareMatrix3.h:1795
SquareMatrixT3< T > & operator+=(const SquareMatrixT3< T > &matrix)
Adds and assigns two matrices.
Definition SquareMatrix3.h:1779
SquareMatrixT3(const T *arrayValues)
Creates a new SquareMatrixT3 object by nine elements.
Definition SquareMatrix3.h:923
bool invert(SquareMatrixT3< T > &invertedMatrix) const
Inverts the matrix and returns the result as parameter.
Definition SquareMatrix3.h:1206
SquareMatrixT3(const SquareMatrixT4< T > &transformation)
Creates a 3x3 square matrix by a given 4x4 square transformation.
Definition SquareMatrix3.h:989
T sum() const
Calculates the sum of elements.
Definition SquareMatrix3.h:1041
SquareMatrixT3< T > & operator*=(const T value)
Multiplies and assigns this matrix with a scalar value.
Definition SquareMatrix3.h:2032
bool isIdentity() const
Returns whether this matrix is an identity matrix.
Definition SquareMatrix3.h:1326
VectorT3< T > diagonal() const
Returns a 3d vector with values of the matrix diagonal.
Definition SquareMatrix3.h:1625
SquareMatrixT3(const VectorT3< T > &diagonal)
Creates a new SquareMatrixT3 object by a given diagonal vector.
Definition SquareMatrix3.h:897
OCEAN_FORCE_INLINE SquareMatrixT3< T > & operator*=(const SquareMatrixT3< T > &matrix)
Multiplies and assigns two matrices.
Definition SquareMatrix3.h:1065
static SquareMatricesT3< T > matrices2matrices(const SquareMatrixT3< U > *matrices, const size_t size)
Converts matrices with specific data type to matrices with different data type.
SquareMatrixT3< T > inverted() const
Returns the inverted matrix of this matrix.
Definition SquareMatrix3.h:1177
bool isOrthonormal(const T epsilon=NumericT< T >::eps()) const
Returns whether this matrix is an orthonormal matrix.
Definition SquareMatrix3.h:1366
bool isSymmetric(const T epsilon=NumericT< T >::eps()) const
Returns whether this matrix is symmetric.
Definition SquareMatrix3.h:1379
bool operator==(const SquareMatrixT3< T > &matrix) const
Returns whether two matrices are identical up to a small epsilon.
Definition SquareMatrix3.h:1755
T & operator()(const unsigned int row, const unsigned int column)
Element operator.
Definition SquareMatrix3.h:1093
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition SquareMatrix3.h:1342
T trace() const
Returns the trace of the matrix which is the sum of the diagonal elements.
Definition SquareMatrix3.h:1292
SquareMatrixT3(const QuaternionT< T > &quaternion)
Creates a new 3x3 matrix object by a given quaternion rotation.
Definition SquareMatrix3.h:842
T operator()(const unsigned int row, const unsigned int column) const
Element operator.
Definition SquareMatrix3.h:1086
This class implements a 4x4 square matrix.
Definition SquareMatrix4.h:85
static void sortHighestToFront3(T &value0, T &value1, T &value2)
Sorts three values so that the highest value will finally be the first value.
Definition base/Utilities.h:724
This class implements a vector with two elements.
Definition Vector2.h:96
This class implements a vector with three elements.
Definition Vector3.h:97
VectorT3< T > perpendicular() const
Returns a vector that is perpendicular to this vector.
Definition Vector3.h:768
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:824
bool normalize()
Normalizes this vector.
Definition Vector3.h:659
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition Vector3.h:609
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:812
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:836
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector3.h:854
T length() const
Returns the length of the vector.
Definition Vector3.h:676
T sqr() const
Returns the square of the vector length.
Definition Vector3.h:682
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition base/Utilities.h:1113
std::vector< SquareMatrixT3< T > > SquareMatricesT3
Definition of a typename alias for vectors with SquareMatrixT3 objects.
Definition SquareMatrix3.h:65
std::vector< SquareMatrix3 > SquareMatrices3
Definition of a vector holding SquareMatrix3 objects.
Definition SquareMatrix3.h:72
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963