matrix4x4.h
#ifndef CMU462_MATRIX4X4_H
#define CMU462_MATRIX4X4_H
#include "CMU462.h"
#include "vector4D.h"
#include <iosfwd>
namespace CMU462 {
class Matrix4x4 {
public:
// The default constructor.
Matrix4x4(void) { }
// Constructor for row major form data.
// Transposes to the internal column major form.
// REQUIRES: data should be of size 16.
Matrix4x4(double * data)
{
for( int i = 0; i < 4; i++ )
for( int j = 0; j < 4; j++ )
{
// Transpostion happens within the () query.
(*this)(i,j) = data[i*4 + j];
}
}
void zero(double val = 0.0);
double det( void ) const;
double norm( void ) const;
static Matrix4x4 identity( void );
// No Cross products for 4 by 4 matrix.
Vector4D& column( int i );
const Vector4D& column( int i ) const;
Matrix4x4 T( void ) const;
Matrix4x4 inv( void ) const;
// accesses element (i,j) of A using 0-based indexing
// where (i, j) is (row, column).
double& operator()( int i, int j );
const double& operator()( int i, int j ) const;
// accesses the ith column of A
Vector4D& operator[]( int i );
const Vector4D& operator[]( int i ) const;
// increments by B
void operator+=( const Matrix4x4& B );
// returns -A
Matrix4x4 operator-( void ) const;
// returns A-B
Matrix4x4 operator-( const Matrix4x4& B ) const;
// returns c*A
Matrix4x4 operator*( double c ) const;
// returns A*B
Matrix4x4 operator*( const Matrix4x4& B ) const;
// returns A*x
Vector4D operator*( const Vector4D& x ) const;
// divides each element by x
void operator/=( double x );
protected:
// 4 by 4 matrices are represented by an array of 4 column vectors.
Vector4D entries[4];
}; // class Matrix3x3
// returns the outer product of u and v.
Matrix4x4 outer( const Vector4D& u, const Vector4D& v );
// returns c*A
Matrix4x4 operator*( double c, const Matrix4x4& A );
// prints entries
std::ostream& operator<<( std::ostream& os, const Matrix4x4& A );
} // namespace CMU462
#endif // CMU462_MATRIX4X4_H
CMU462
Definition: CMU462.h:8
CMU462::Matrix4x4::inv
Matrix4x4 inv(void) const
Returns the inverse of A.
Definition: matrix4x4.cpp:195
CMU462::Vector4D
Defines 4D standard vectors.
Definition: vector4D.h:15
CMU462::Matrix4x4::zero
void zero(double val=0.0)
Sets all elements to val.
Definition: matrix4x4.cpp:26
CMU462::Matrix4x4::identity
static Matrix4x4 identity(void)
Returns a fresh 4x4 identity matrix.
Definition: matrix4x4.cpp:235
CMU462::Matrix4x4::column
Vector4D & column(int i)
Returns the ith column.
Definition: matrix4x4.cpp:275
CMU462::Matrix4x4
Defines a 4x4 matrix.
Definition: matrix4x4.h:22
CMU462::Matrix4x4::norm
double norm(void) const
Returns the Frobenius norm of A.
Definition: matrix4x4.cpp:53
CMU462::Matrix4x4::det
double det(void) const
Returns the determinant of A.
Definition: matrix4x4.cpp:34
CMU462::Matrix4x4::T
Matrix4x4 T(void) const
Returns the transpose of A.
Definition: matrix4x4.cpp:182