CMU462 Library  1.0
15-462/15-662: Computer Graphics (Fall 2015)
matrix3x3.h
1 #ifndef CMU462_MATRIX3X3_H
2 #define CMU462_MATRIX3X3_H
3 
4 #include "CMU462.h"
5 #include "vector3D.h"
6 
7 #include <iosfwd>
8 
9 namespace CMU462 {
10 
15 class Matrix3x3 {
16 
17  public:
18 
19  // The default constructor.
20  Matrix3x3(void) { }
21 
22  // Constructor for row major form data.
23  // Transposes to the internal column major form.
24  // REQUIRES: data should be of size 9 for a 3 by 3 matrix..
25  Matrix3x3(double * data)
26  {
27  for( int i = 0; i < 3; i++ ) {
28  for( int j = 0; j < 3; j++ ) {
29  // Transpostion happens within the () query.
30  (*this)(i,j) = data[i*3 + j];
31  }
32  }
33  }
34 
38  void zero(double val = 0.0 );
39 
43  double det( void ) const;
44 
48  double norm( void ) const;
49 
53  static Matrix3x3 identity( void );
54 
58  static Matrix3x3 crossProduct( const Vector3D& u );
59 
63  Vector3D& column( int i );
64  const Vector3D& column( int i ) const;
65 
69  Matrix3x3 T( void ) const;
70 
74  Matrix3x3 inv( void ) const;
75 
76  // accesses element (i,j) of A using 0-based indexing
77  double& operator()( int i, int j );
78  const double& operator()( int i, int j ) const;
79 
80  // accesses the ith column of A
81  Vector3D& operator[]( int i );
82  const Vector3D& operator[]( int i ) const;
83 
84  // increments by B
85  void operator+=( const Matrix3x3& B );
86 
87  // returns -A
88  Matrix3x3 operator-( void ) const;
89 
90  // returns A-B
91  Matrix3x3 operator-( const Matrix3x3& B ) const;
92 
93  // returns c*A
94  Matrix3x3 operator*( double c ) const;
95 
96  // returns A*B
97  Matrix3x3 operator*( const Matrix3x3& B ) const;
98 
99  // returns A*x
100  Vector3D operator*( const Vector3D& x ) const;
101 
102  // divides each element by x
103  void operator/=( double x );
104 
105  protected:
106 
107  // column vectors
108  Vector3D entries[3];
109 
110 }; // class Matrix3x3
111 
112 // returns the outer product of u and v
113 Matrix3x3 outer( const Vector3D& u, const Vector3D& v );
114 
115 // returns c*A
116 Matrix3x3 operator*( double c, const Matrix3x3& A );
117 
118 // prints entries
119 std::ostream& operator<<( std::ostream& os, const Matrix3x3& A );
120 
121 } // namespace CMU462
122 
123 #endif // CMU462_MATRIX3X3_H
double det(void) const
Returns the determinant of A.
Definition: matrix3x3.cpp:31
Definition: CMU462.h:8
Defines 3D vectors.
Definition: vector3D.h:14
static Matrix3x3 identity(void)
Returns the 3x3 identity matrix.
Definition: matrix3x3.cpp:181
Vector3D & column(int i)
Returns the ith column.
Definition: matrix3x3.cpp:234
static Matrix3x3 crossProduct(const Vector3D &u)
Returns a matrix representing the (left) cross product with u.
Definition: matrix3x3.cpp:191
Matrix3x3 inv(void) const
Returns the inverse of A.
Definition: matrix3x3.cpp:157
Matrix3x3 T(void) const
Returns the transpose of A.
Definition: matrix3x3.cpp:144
void zero(double val=0.0)
Sets all elements to val.
Definition: matrix3x3.cpp:26
Defines a 3x3 matrix.
Definition: matrix3x3.h:15
double norm(void) const
Returns the Frobenius norm of A.
Definition: matrix3x3.cpp:39