matrix3x3.h
#ifndef CMU462_MATRIX3X3_H
#define CMU462_MATRIX3X3_H
#include "CMU462.h"
#include "vector3D.h"
#include <iosfwd>
namespace CMU462 {
class Matrix3x3 {
public:
// The default constructor.
Matrix3x3(void) { }
// Constructor for row major form data.
// Transposes to the internal column major form.
// REQUIRES: data should be of size 9 for a 3 by 3 matrix..
Matrix3x3(double * data)
{
for( int i = 0; i < 3; i++ ) {
for( int j = 0; j < 3; j++ ) {
// Transpostion happens within the () query.
(*this)(i,j) = data[i*3 + j];
}
}
}
void zero(double val = 0.0 );
double det( void ) const;
double norm( void ) const;
static Matrix3x3 identity( void );
static Matrix3x3 crossProduct( const Vector3D& u );
Vector3D& column( int i );
const Vector3D& column( int i ) const;
Matrix3x3 T( void ) const;
Matrix3x3 inv( void ) const;
// accesses element (i,j) of A using 0-based indexing
double& operator()( int i, int j );
const double& operator()( int i, int j ) const;
// accesses the ith column of A
Vector3D& operator[]( int i );
const Vector3D& operator[]( int i ) const;
// increments by B
void operator+=( const Matrix3x3& B );
// returns -A
Matrix3x3 operator-( void ) const;
// returns A-B
Matrix3x3 operator-( const Matrix3x3& B ) const;
// returns c*A
Matrix3x3 operator*( double c ) const;
// returns A*B
Matrix3x3 operator*( const Matrix3x3& B ) const;
// returns A*x
Vector3D operator*( const Vector3D& x ) const;
// divides each element by x
void operator/=( double x );
protected:
// column vectors
Vector3D entries[3];
}; // class Matrix3x3
// returns the outer product of u and v
Matrix3x3 outer( const Vector3D& u, const Vector3D& v );
// returns c*A
Matrix3x3 operator*( double c, const Matrix3x3& A );
// prints entries
std::ostream& operator<<( std::ostream& os, const Matrix3x3& A );
} // namespace CMU462
#endif // CMU462_MATRIX3X3_H
CMU462::Matrix3x3::det
double det(void) const
Returns the determinant of A.
Definition: matrix3x3.cpp:31
CMU462
Definition: CMU462.h:8
CMU462::Vector3D
Defines 3D vectors.
Definition: vector3D.h:14
CMU462::Matrix3x3::identity
static Matrix3x3 identity(void)
Returns the 3x3 identity matrix.
Definition: matrix3x3.cpp:181
CMU462::Matrix3x3::column
Vector3D & column(int i)
Returns the ith column.
Definition: matrix3x3.cpp:234
CMU462::Matrix3x3::crossProduct
static Matrix3x3 crossProduct(const Vector3D &u)
Returns a matrix representing the (left) cross product with u.
Definition: matrix3x3.cpp:191
CMU462::Matrix3x3::inv
Matrix3x3 inv(void) const
Returns the inverse of A.
Definition: matrix3x3.cpp:157
CMU462::Matrix3x3::T
Matrix3x3 T(void) const
Returns the transpose of A.
Definition: matrix3x3.cpp:144
CMU462::Matrix3x3::zero
void zero(double val=0.0)
Sets all elements to val.
Definition: matrix3x3.cpp:26
CMU462::Matrix3x3
Defines a 3x3 matrix.
Definition: matrix3x3.h:15
CMU462::Matrix3x3::norm
double norm(void) const
Returns the Frobenius norm of A.
Definition: matrix3x3.cpp:39