Browse Source

Documented Matrix and Vector algorithms.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
c5b38c9f1a
  1. 2
      Doxyfile
  2. 18
      src/Math/Matrix.h
  3. 18
      src/Math/Vector.h
  4. 15
      src/Math/Vector3.h

2
Doxyfile

@ -1264,7 +1264,7 @@ PAPER_TYPE = a4
# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
# packages that should be included in the LaTeX output.
EXTRA_PACKAGES =
EXTRA_PACKAGES = amsmath
# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
# the generated latex document. The header should contain everything until

18
src/Math/Matrix.h

@ -209,14 +209,26 @@ template<class T, size_t size> class Matrix {
/**
* @brief Determinant
*
* Computed recursively using Laplace's formula expanded down to 2x2
* matrix, where the determinant is computed directly. Complexity is
* O(n!), the same as when computing the determinant directly.
* Computed recursively using Laplace's formula:
* @f[
* \det(A) = \sum_{j=1}^n (-1)^{i+j} a_{i,j} \det(A^{i,j})
* @f]
* @f$ A^{i, j} @f$ is matrix without i-th row and j-th column, see
* ij(). The formula is expanded down to 2x2 matrix, where the
* determinant is computed directly:
* @f[
* \det(A) = a_{0, 0} a_{1, 1} - a_{1, 0} a_{0, 1}
* @f]
*/
inline T determinant() const { return Implementation::MatrixDeterminant<T, size>()(*this); }
/**
* @brief Inverted matrix
*
* Computed using Cramer's rule:
* @f[
* A^{-1} = \frac{1}{\det(A)} Adj(A)
* @f]
*/
Matrix<T, size> inverted() const {
Matrix<T, size> out(Zero);

18
src/Math/Vector.h

@ -37,7 +37,7 @@ template<class T, size_t size> class Vector {
const static size_t Size = size; /**< @brief %Vector size */
/**
* @brief Vector from array
* @brief %Vector from array
* @return Reference to the data as if it was Vector, thus doesn't
* perform any copying.
*
@ -53,7 +53,13 @@ template<class T, size_t size> class Vector {
return *reinterpret_cast<const Vector<T, size>*>(data);
}
/** @brief Dot product */
/**
* @brief Dot product
*
* @f[
* a \cdot b = \sum_{i=1}^n a_ib_i
* @f]
*/
static T dot(const Vector<T, size>& a, const Vector<T, size>& b) {
T out(0);
@ -63,7 +69,13 @@ template<class T, size_t size> class Vector {
return out;
}
/** @brief Angle between vectors */
/**
* @brief Angle between vectors
*
* @f[
* \phi = \frac{a \cdot b}{|a| \cdot |b|}
* @f]
*/
inline static T angle(const Vector<T, size>& a, const Vector<T, size>& b) {
return acos(dot(a, b)/(a.length()*b.length()));
}

15
src/Math/Vector3.h

@ -36,16 +36,23 @@ template<class T> class Vector3: public Vector<T, 3> {
return *reinterpret_cast<const Vector3<T>*>(data);
}
/** @brief Vector in direction of X axis */
/** @brief %Vector in direction of X axis */
inline constexpr static Vector3<T> xAxis(T length = T(1)) { return Vector3<T>(length, T(), T()); }
/** @brief Vector in direction of Y axis */
/** @brief %Vector in direction of Y axis */
inline constexpr static Vector3<T> yAxis(T length = T(1)) { return Vector3<T>(T(), length, T()); }
/** @brief Vector in direction of Z axis */
/** @brief %Vector in direction of Z axis */
inline constexpr static Vector3<T> zAxis(T length = T(1)) { return Vector3<T>(T(), T(), length); }
/** @brief Cross product */
/**
* @brief Cross product
*
* @f[
* \begin{pmatrix} c_1 \\ c_2 \\ c_3 \end{pmatrix} =
* \begin{pmatrix}a_2b_3 - a_3b_2 \\ a_3b_1 - a_1b_3 \\ a_1b_2 - a_2b_1 \end{pmatrix}
* @f]
*/
constexpr static Vector3<T> cross(const Vector3<T>& a, const Vector3<T>& b) {
return Vector3<T>(a[1]*b[2]-a[2]*b[1],
a[2]*b[0]-a[0]*b[2],

Loading…
Cancel
Save