QCAD
Open Source 2D CAD
RMatrix Class Reference

Simple matrix class. More...

#include <RMatrix.h>

Public Member Functions

void clear ()
 Deletes the elements of this matrix and resets the matrix size to 0/0. More...
 
double get (int r, int c) const
 
RMatrix getAppended (const RMatrix &v) const
 Appends matrix v to the right side of this matrix and returns the new matrix. More...
 
int getCols () const
 
RMatrix getInverse () const
 
double getRotationAngle () const
 
int getRows () const
 
RMatrix getTransposed () const
 
double getUniformScaleFactor () const
 
void init (int r, int c)
 Initializes the matrix for the given size and resets all elements to 0. More...
 
bool isRotationAndUniformScale () const
 
bool isValid () const
 
RMatrix multiplyWith (const RMatrix &w) const
 
RVector multiplyWith (const RVector &w) const
 
RMatrix multiplyWith (double w) const
 
RMatrix operator* (const RMatrix &other) const
 Multiplies two matrices. More...
 
RMatrix operator* (double s) const
 
RMatrix operator*= (double f)
 Multiplies all elements of this matrix with the given factor and returns this matrix. More...
 
RMatrixoperator= (const RMatrix &other)
 Assignment operator. More...
 
bool operator== (const RMatrix &other) const
 Comparison. More...
 
double * operator[] (int i)
 
void reset ()
 Resets all elements to 0. More...
 
 RMatrix ()
 Copyright (c) 2011-2018 by Andrew Mustun. More...
 
 RMatrix (const RMatrix &other)
 Copy constructor. More...
 
 RMatrix (int r, int c)
 Creates a matrix with r rows and c columns. More...
 
bool rref ()
 Changes this matrix into its rref. More...
 
void set (int r, int c, double v)
 Sets the element at the given row/column to the given value v. More...
 
void set2x3 (double a11, double a12, double a13, double a21, double a22, double a23)
 Sets the dimension of this matrix to 2x3 and the elements to the given elements. More...
 
void set3x1 (double a11, double a21, double a31)
 Sets the dimension of this matrix to 3x1 and the elements to the given elements. More...
 
void set3x3 (double a11, double a12, double a13, double a21, double a22, double a23, double a31, double a32, double a33)
 Sets the dimension of this matrix to 3x3 and the elements to the given elements. More...
 
 ~RMatrix ()
 Deletes the matrix. More...
 

Static Public Member Functions

static RMatrix create2x2 (double a11, double a12, double a21, double a22)
 
static RMatrix create2x3 (double a11, double a12, double a13, double a21, double a22, double a23)
 
static RMatrix create3x1 (double a11, double a21, double a31)
 
static RMatrix create3x3 (double a11, double a12, double a13, double a21, double a22, double a23, double a31, double a32, double a33)
 
static RMatrix createIdentity (int size)
 
static RMatrix createIdentity2x2 ()
 
static RMatrix createIdentity3x3 ()
 
static RMatrix createRotation (double angle)
 

Protected Member Functions

void addRow (int r, double factor, int r2)
 Adds to row r factor times row r2. More...
 
int getPivotCol (int r)
 
int getPivotRow (int startRow)
 
void multiplyRow (int r, double factor)
 Multiplies row r with factor. More...
 
bool ref (int startRow)
 Changes this matrix into its ref. More...
 
void swapRows (int r1, int r2)
 Swaps the given two rows. More...
 

Private Attributes

int cols
 
double ** m
 
int rows
 

Detailed Description

Simple matrix class.

Scriptable:\nThis class is available in script environments.\n
Copyable:\nObjects are cleaned up automatically by the garbage collector of the script engine.\n

Constructor & Destructor Documentation

◆ RMatrix() [1/3]

RMatrix::RMatrix ( )

Copyright (c) 2011-2018 by Andrew Mustun.

All rights reserved.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with QCAD. Creates and empty matrix (zero columns and zero rows).

◆ RMatrix() [2/3]

RMatrix::RMatrix ( int  r,
int  c 
)

Creates a matrix with r rows and c columns.

All elements are reset to 0.

Parameters
rnumber of rows
cnumber of columns

◆ RMatrix() [3/3]

RMatrix::RMatrix ( const RMatrix other)

Copy constructor.

◆ ~RMatrix()

RMatrix::~RMatrix ( )

Deletes the matrix.

Member Function Documentation

◆ addRow()

void RMatrix::addRow ( int  r,
double  factor,
int  r2 
)
protected

Adds to row r factor times row r2.

Parameters
rthe row
r2the row 2
factorThe factor to apply to r2 before it is added to row r.

◆ clear()

void RMatrix::clear ( )

Deletes the elements of this matrix and resets the matrix size to 0/0.

◆ create2x2()

RMatrix RMatrix::create2x2 ( double  a11,
double  a12,
double  a21,
double  a22 
)
static
Returns
A matrix with 2 rows and 2 columns: $ \left( \begin{array}{ccc} a_{11} & a_{12} \\ a_{21} & a_{22} \end{array} \right) $

◆ create2x3()

RMatrix RMatrix::create2x3 ( double  a11,
double  a12,
double  a13,
double  a21,
double  a22,
double  a23 
)
static
Returns
A matrix with 2 rows and 3 columns: $ \left( \begin{array}{ccc} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \end{array} \right) $

◆ create3x1()

RMatrix RMatrix::create3x1 ( double  a11,
double  a21,
double  a31 
)
static
Returns
A matrix with 3 rows and 1 column (vector): $ \left( \begin{array}{ccc} a_{11} \\ a_{21} \\ a_{31} \end{array} \right) $

◆ create3x3()

RMatrix RMatrix::create3x3 ( double  a11,
double  a12,
double  a13,
double  a21,
double  a22,
double  a23,
double  a31,
double  a32,
double  a33 
)
static
Returns
A matrix with 3 rows and 3 columns: $ \left( \begin{array}{ccc} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{array} \right) $

◆ createIdentity()

RMatrix RMatrix::createIdentity ( int  size)
static
Returns
An identity matrix with size rows and size columns: $ \left( \begin{array}{cccc} 1 & 0 & 0 & \ldots \\ 0 & 1 & 0 & \ldots \\ 0 & 0 & 1 & \ldots \\ \ldots & \ldots & \ldots & \ldots \end{array} \right) $

◆ createIdentity2x2()

RMatrix RMatrix::createIdentity2x2 ( )
static
Returns
An identity matrix with 2 rows and 2 columns: $ \left( \begin{array}{ccc} 1 & 0 \\ 0 & 1 \end{array} \right) $

◆ createIdentity3x3()

RMatrix RMatrix::createIdentity3x3 ( )
static
Returns
An identity matrix with 3 rows and 3 columns: $ \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right) $

◆ createRotation()

RMatrix RMatrix::createRotation ( double  angle)
static

◆ get()

double RMatrix::get ( int  r,
int  c 
) const
Parameters
rthe row
cthe column
Returns
The element at the given row/column.

◆ getAppended()

RMatrix RMatrix::getAppended ( const RMatrix v) const

Appends matrix v to the right side of this matrix and returns the new matrix.

This matrix is not affected.

Parameters
vthe matrix to append to this matrix

◆ getCols()

int RMatrix::getCols ( ) const
inline
Returns
Number of columns of this matrix.

◆ getInverse()

RMatrix RMatrix::getInverse ( ) const
Returns
The inverse matrix of this matrix $A^{-1}$ or an empty matrix if this matrix is not invertible.

◆ getPivotCol()

int RMatrix::getPivotCol ( int  r)
protected
Parameters
rthe row
Returns
The pivot column of the given matrix row r.

◆ getPivotRow()

int RMatrix::getPivotRow ( int  startRow)
protected
Parameters
startRowthe start row
Returns
The pivot row of this matrix, starting with the given row startRow.

◆ getRotationAngle()

double RMatrix::getRotationAngle ( ) const

◆ getRows()

int RMatrix::getRows ( ) const
inline
Returns
Number of rows of this matrix.

◆ getTransposed()

RMatrix RMatrix::getTransposed ( ) const
Returns
The transposed matrix $A^T$. This matrix is not affected.

◆ getUniformScaleFactor()

double RMatrix::getUniformScaleFactor ( ) const

◆ init()

void RMatrix::init ( int  r,
int  c 
)

Initializes the matrix for the given size and resets all elements to 0.

◆ isRotationAndUniformScale()

bool RMatrix::isRotationAndUniformScale ( ) const

◆ isValid()

bool RMatrix::isValid ( ) const
Returns
True if this matrix is a valid matrix (more than 0 columns and rows).

◆ multiplyRow()

void RMatrix::multiplyRow ( int  r,
double  factor 
)
protected

Multiplies row r with factor.

Parameters
rthe row
factorthe factor to apply to the row

◆ multiplyWith() [1/3]

RMatrix RMatrix::multiplyWith ( const RMatrix w) const
Returns
$A \cdot W$ This matrix is not affected.

◆ multiplyWith() [2/3]

RVector RMatrix::multiplyWith ( const RVector w) const

◆ multiplyWith() [3/3]

RMatrix RMatrix::multiplyWith ( double  w) const

◆ operator*() [1/2]

RMatrix RMatrix::operator* ( const RMatrix other) const

Multiplies two matrices.

Non-Scriptable:\nThis function is not available in script environments.\n

◆ operator*() [2/2]

RMatrix RMatrix::operator* ( double  s) const

◆ operator*=()

RMatrix RMatrix::operator*= ( double  f)

Multiplies all elements of this matrix with the given factor and returns this matrix.

Non-Scriptable:\nThis function is not available in script environments.\n

◆ operator=()

RMatrix & RMatrix::operator= ( const RMatrix other)

Assignment operator.

Non-Scriptable:\nThis function is not available in script environments.\n

◆ operator==()

bool RMatrix::operator== ( const RMatrix other) const

Comparison.

Non-Scriptable:\nThis function is not available in script environments.\n

All elements of the matrix as well as the matrix dimensions have to match for the two matrices to be equal.

◆ operator[]()

double* RMatrix::operator[] ( int  i)
Non-Scriptable:\nThis function is not available in script environments.\n

◆ ref()

bool RMatrix::ref ( int  startRow)
protected

Changes this matrix into its ref.

Returns
True on success.

◆ reset()

void RMatrix::reset ( )

Resets all elements to 0.

◆ rref()

bool RMatrix::rref ( )

Changes this matrix into its rref.

See also
http://en.wikipedia.org/wiki/Rref#Reduced_row_echelon_form
Returns
True on success.

◆ set()

void RMatrix::set ( int  r,
int  c,
double  v 
)

Sets the element at the given row/column to the given value v.

Parameters
rthe row
cthe column
vthe new value at the given row / column position

◆ set2x3()

void RMatrix::set2x3 ( double  a11,
double  a12,
double  a13,
double  a21,
double  a22,
double  a23 
)

Sets the dimension of this matrix to 2x3 and the elements to the given elements.

◆ set3x1()

void RMatrix::set3x1 ( double  a11,
double  a21,
double  a31 
)

Sets the dimension of this matrix to 3x1 and the elements to the given elements.

◆ set3x3()

void RMatrix::set3x3 ( double  a11,
double  a12,
double  a13,
double  a21,
double  a22,
double  a23,
double  a31,
double  a32,
double  a33 
)

Sets the dimension of this matrix to 3x3 and the elements to the given elements.

◆ swapRows()

void RMatrix::swapRows ( int  r1,
int  r2 
)
protected

Swaps the given two rows.

Parameters
r1the row 1
r2the row 2

Member Data Documentation

◆ cols

int RMatrix::cols
private

◆ m

double** RMatrix::m
private

◆ rows

int RMatrix::rows
private

The documentation for this class was generated from the following files: