-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.h
executable file
·57 lines (44 loc) · 2.08 KB
/
matrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef OAB_MATRIX_H_INCLUDED
#define OAB_MATRIX_H_INCLUDED
#include <iostream>
#include <cmath>
#include <stdexcept>
// Container for n x m dimensional matrices of doubles.
class Matrix{
private:
int rows, columns; // IMPORTANT: We number rows and columns from 1 onwards. First column = 1, etc.
double *mdata; // C-Style array of doubles in which we store the matrix.
public:
// Default constructor
Matrix(){ mdata = 0; rows = columns = 0; }
// Parameterised constructors
Matrix(int t_rows, int t_columns);
// Copy constructor
Matrix(const Matrix &mat); // Performs a deep copy.
// Destructor
virtual ~Matrix(){ delete mdata; }
// Public access functions
// const variants
int getRows() const { return rows; }
int getColumns() const { return columns; }
virtual const double & index(int row, int column) const; // returns a const reference to matrix member at row, column. Rows & columns are numbered from 1.
virtual const double & operator()(int row, int column) const; // vanity for index function
// non-const variants
virtual double & index(int row, int column); // returns a reference to matrix member at row, column
virtual double & operator()(int row, int column); // vanity for index function
// Assignment function
virtual Matrix & operator=(const Matrix &mat); // performs deep copy
// Arithmetical operators
virtual Matrix operator+(const Matrix &mat) const;
virtual Matrix operator-(const Matrix &mat) const;
virtual Matrix operator*(const Matrix &mat) const;
virtual Matrix operator*(double i) const;
// Boolean operators
bool operator==(const Matrix &mat) const; // returns true if every element of matrices match
};
// Helper functions for transfomation of 2D co-ordinates.
Matrix RotMatrix(double theta); // Rotation of theta degrees clockwise about the origin.
Matrix ReflectMatrix(double x, double y); // Reflection parallel to a line passing through x,y from the origin.
Matrix ShearMatrix(double x, double y);
Matrix ScaleMatrix(double x, double y); // Geometrically scales about the origin.
#endif