Rhino C++ API  7.18
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ON_Matrix Class Reference

#include <opennurbs_matrix.h>

Public Member Functions

 ON_Matrix ()
 
 ON_Matrix (const ON_Matrix &)
 
 ON_Matrix (const ON_Xform &)
 
 ON_Matrix (int row_count, int col_count)
 
 ON_Matrix (int row_count, int col_count, double **M, bool bDestructorFreeM)
 
 ON_Matrix (int, int, int, int)
 
virtual ~ON_Matrix ()
 
bool Add (const ON_Matrix &A, const ON_Matrix &B)
 
bool BackSolve (double, int, const double *, double *) const
 
bool BackSolve (double, int, const ON_3dPoint *, ON_3dPoint *) const
 
bool BackSolve (double, int, int, int, const double *, int, double *) const
 
int ColCount () const
 
void ColOp (int, double, int)
 
void ColScale (int, double)
 
bool Create (int row_count, int col_count, double **M, bool bDestructorFreeM)
 
bool Create (int, int)
 
bool Create (int, int, int, int)
 
void Destroy ()
 
void EmergencyDestroy ()
 call if memory pool used matrix by becomes invalid More...
 
bool Invert (double)
 
bool IsColOrthoganal () const
 
bool IsColOrthoNormal () const
 
bool IsRowOrthoganal () const
 
bool IsRowOrthoNormal () const
 
int IsSquare () const
 returns 0 for no and m_row_count (= m_col_count) for yes More...
 
bool IsValid () const
 
int MaxCount () const
 largest of row and column count More...
 
int MinCount () const
 smallest of row and column count More...
 
bool Multiply (const ON_Matrix &A, const ON_Matrix &B)
 
ON_Matrixoperator= (const ON_Matrix &)
 
ON_Matrixoperator= (const ON_Xform &)
 
double * operator[] (int)
 
const double * operator[] (int) const
 
int RowCount () const
 
void RowOp (int, double, int)
 
int RowReduce (double, double &, double &)
 
int RowReduce (double, double *, double *=nullptr)
 
int RowReduce (double, int, int, double *, double *=nullptr)
 
int RowReduce (double, ON_3dPoint *, double *=nullptr)
 
void RowScale (int, double)
 
bool Scale (double s)
 
void SetDiagonal (const double *)
 sets diagonal values and zeros off diagonal values More...
 
void SetDiagonal (const ON_SimpleArray< double > &)
 sets size to length X lengthdiagonal values and zeros off diagonal values More...
 
void SetDiagonal (double)
 sets diagonal value and zeros off diagonal values More...
 
void SetDiagonal (int, const double *)
 sets size to count x count and diagonal values and zeros off diagonal values More...
 
bool SwapCols (int, int)
 ints are col indices to swap More...
 
bool SwapRows (int, int)
 ints are row indices to swap More...
 
bool Transpose ()
 
unsigned int UnsignedColCount () const
 
unsigned int UnsignedMaxCount () const
 largest of row and column count More...
 
unsigned int UnsignedMinCount () const
 smallest of row and column count More...
 
unsigned int UnsignedRowCount () const
 
void Zero ()
 

Static Public Member Functions

static double ** Allocate (unsigned int row_count, unsigned int col_count)
 
static void Deallocate (double **M)
 

Public Attributes

double ** m = nullptr
 

Constructor & Destructor Documentation

◆ ON_Matrix() [1/6]

ON_Matrix::ON_Matrix ( )

◆ ON_Matrix() [2/6]

ON_Matrix::ON_Matrix ( int  row_count,
int  col_count 
)

◆ ON_Matrix() [3/6]

ON_Matrix::ON_Matrix ( int  ,
int  ,
int  ,
int   
)

◆ ON_Matrix() [4/6]

ON_Matrix::ON_Matrix ( const ON_Xform )

◆ ON_Matrix() [5/6]

ON_Matrix::ON_Matrix ( const ON_Matrix )

◆ ON_Matrix() [6/6]

ON_Matrix::ON_Matrix ( int  row_count,
int  col_count,
double **  M,
bool  bDestructorFreeM 
)

Description: This constructor is for experts who have storage for a matrix and need to use it in ON_Matrix form. Parameters: row_count - [in] col_count - [in] M - [in] bDestructorFreeM - [in] If true, ~ON_Matrix will call onfree(M). If false, caller is managing M's memory. Remarks: ON_Matrix functions that increase the value of row_count or col_count will fail on a matrix created with this constructor.

◆ ~ON_Matrix()

virtual ON_Matrix::~ON_Matrix ( )
virtual

Member Function Documentation

◆ Add()

bool ON_Matrix::Add ( const ON_Matrix A,
const ON_Matrix B 
)

Description: Set this = A+B. Parameters: A - [in] (Can be this) B - [in] (Can be this) Returns: True when A and B are mXn matrices; in which case "this" will be an mXn matrix = A+B. False when A and B have different sizes.

◆ Allocate()

static double** ON_Matrix::Allocate ( unsigned int  row_count,
unsigned int  col_count 
)
static

Returns: A row_count X col_count martix on the heap that can be deleted by calling ON_Matrix::Deallocate().

◆ BackSolve() [1/3]

bool ON_Matrix::BackSolve ( double  ,
int  ,
const double *  ,
double *   
) const

Description: Solve M*X=B where M is upper triangular with a unit diagonal and B is a column of values. Parameters: zero_tolerance - in used to test for "zero" values in B in under determined systems of equations. Bsize - [in] (>=m_row_count) length of B. The values in B[m_row_count],...,B[Bsize-1] are tested to make sure they are "zero". B - [in] array of length Bsize. X - [out] array of length m_col_count. Solutions returned here. Remarks: Actual values M[i][j] with i <= j are ignored. M[i][i] is assumed to be one and M[i][j] i<j is assumed to be zero. For square M, B and X can point to the same memory. See Also: ON_Matrix::RowReduce

◆ BackSolve() [2/3]

bool ON_Matrix::BackSolve ( double  ,
int  ,
const ON_3dPoint ,
ON_3dPoint  
) const

Description: Solve M*X=B where M is upper triangular with a unit diagonal and B is a column of 3d points. Parameters: zero_tolerance - in used to test for "zero" values in B in under determined systems of equations. Bsize - [in] (>=m_row_count) length of B. The values in B[m_row_count],...,B[Bsize-1] are tested to make sure they are "zero". B - [in] array of length Bsize. X - [out] array of length m_col_count. Solutions returned here. Remarks: Actual values M[i][j] with i <= j are ignored. M[i][i] is assumed to be one and M[i][j] i<j is assumed to be zero. For square M, B and X can point to the same memory. See Also: ON_Matrix::RowReduce

◆ BackSolve() [3/3]

bool ON_Matrix::BackSolve ( double  ,
int  ,
int  ,
int  ,
const double *  ,
int  ,
double *   
) const

Description: Solve M*X=B where M is upper triangular with a unit diagonal and B is a column of points Parameters: zero_tolerance - in used to test for "zero" values in B in under determined systems of equations. pt_dim - [in] dimension of points Bsize - [in] (>=m_row_count) number of points in B[]. The points correspoinding to indices m_row_count, ..., (Bsize-1) are tested to make sure they are "zero". Bpt_stride - [in] stride between B points (>=pt_dim) Bpt - [in/out] array of m_row_count*Bpt_stride values. The i-th B point is (Bpt[i*Bpt_stride],...,Bpt[i*Bpt_stride+pt_dim-1]). Xpt_stride - [in] stride between X points (>=pt_dim) Xpt - [out] array of m_col_count*Xpt_stride values. The i-th X point is (Xpt[i*Xpt_stride],...,Xpt[i*Xpt_stride+pt_dim-1]). Remarks: Actual values M[i][j] with i <= j are ignored. M[i][i] is assumed to be one and M[i][j] i<j is assumed to be zero. For square M, B and X can point to the same memory. See Also: ON_Matrix::RowReduce

◆ ColCount()

int ON_Matrix::ColCount ( ) const

◆ ColOp()

void ON_Matrix::ColOp ( int  ,
double  ,
int   
)

◆ ColScale()

void ON_Matrix::ColScale ( int  ,
double   
)

◆ Create() [1/3]

bool ON_Matrix::Create ( int  row_count,
int  col_count,
double **  M,
bool  bDestructorFreeM 
)

Description: This constructor is for experts who have storage for a matrix and need to use it in ON_Matrix form. Parameters: row_count - [in] col_count - [in] M - [in] bDestructorFreeM - [in] If true, ~ON_Matrix will call onfree(M). If false, caller is managing M's memory. Remarks: ON_Matrix functions that increase the value of row_count or col_count will fail on a matrix created with this constructor.

◆ Create() [2/3]

bool ON_Matrix::Create ( int  ,
int   
)

◆ Create() [3/3]

bool ON_Matrix::Create ( int  ,
int  ,
int  ,
int   
)

◆ Deallocate()

static void ON_Matrix::Deallocate ( double **  M)
static

◆ Destroy()

void ON_Matrix::Destroy ( )

◆ EmergencyDestroy()

void ON_Matrix::EmergencyDestroy ( )

call if memory pool used matrix by becomes invalid

◆ Invert()

bool ON_Matrix::Invert ( double  )

◆ IsColOrthoganal()

bool ON_Matrix::IsColOrthoganal ( ) const

◆ IsColOrthoNormal()

bool ON_Matrix::IsColOrthoNormal ( ) const

◆ IsRowOrthoganal()

bool ON_Matrix::IsRowOrthoganal ( ) const

◆ IsRowOrthoNormal()

bool ON_Matrix::IsRowOrthoNormal ( ) const

◆ IsSquare()

int ON_Matrix::IsSquare ( ) const

returns 0 for no and m_row_count (= m_col_count) for yes

◆ IsValid()

bool ON_Matrix::IsValid ( ) const

◆ MaxCount()

int ON_Matrix::MaxCount ( ) const

largest of row and column count

◆ MinCount()

int ON_Matrix::MinCount ( ) const

smallest of row and column count

◆ Multiply()

bool ON_Matrix::Multiply ( const ON_Matrix A,
const ON_Matrix B 
)

Description: Set this = A*B. Parameters: A - [in] (Can be this) B - [in] (Can be this) Returns: True when A is an mXk matrix and B is a k X n matrix; in which case "this" will be an mXn matrix = A*B. False when A.ColCount() != B.RowCount().

◆ operator=() [1/2]

ON_Matrix& ON_Matrix::operator= ( const ON_Matrix )

◆ operator=() [2/2]

ON_Matrix& ON_Matrix::operator= ( const ON_Xform )

◆ operator[]() [1/2]

double* ON_Matrix::operator[] ( int  )

ON_Matrix[i][j] = value at row i and column j 0 <= i < RowCount() 0 <= j < ColCount()

◆ operator[]() [2/2]

const double* ON_Matrix::operator[] ( int  ) const

◆ RowCount()

int ON_Matrix::RowCount ( ) const

◆ RowOp()

void ON_Matrix::RowOp ( int  ,
double  ,
int   
)

◆ RowReduce() [1/4]

int ON_Matrix::RowReduce ( double  ,
double &  ,
double &   
)

Description: Row reduce a matrix to calculate rank and determinant. Parameters: zero_tolerance - in zero tolerance for pivot test If the absolute value of a pivot is <= zero_tolerance, then the pivot is assumed to be zero. determinant - [out] value of determinant is returned here. pivot - [out] value of the smallest pivot is returned here Returns: Rank of the matrix. Remarks: The matrix itself is row reduced so that the result is an upper triangular matrix with 1's on the diagonal.

◆ RowReduce() [2/4]

int ON_Matrix::RowReduce ( double  ,
double *  ,
double *  = nullptr 
)

Description: Row reduce a matrix as the first step in solving M*X=B where B is a column of values. Parameters: zero_tolerance - in zero tolerance for pivot test If the absolute value of a pivot is <= zero_tolerance, then the pivot is assumed to be zero. B - [in/out] an array of m_row_count values that is row reduced with the matrix. determinant - [out] value of determinant is returned here. pivot - [out] If not nullptr, then the value of the smallest pivot is returned here Returns: Rank of the matrix. Remarks: The matrix itself is row reduced so that the result is an upper triangular matrix with 1's on the diagonal. Example: Solve M*X=B; double B[m] = ...; double B[n] = ...; ON_Matrix M(m,n) = ...; M.RowReduce(ON_ZERO_TOLERANCE,B); ///< modifies M and B M.BackSolve(m,B,X); ///< solution is in X See Also: ON_Matrix::BackSolve

◆ RowReduce() [3/4]

int ON_Matrix::RowReduce ( double  ,
int  ,
int  ,
double *  ,
double *  = nullptr 
)

Description: Row reduce a matrix as the first step in solving M*X=B where B is a column arbitrary dimension points. Parameters: zero_tolerance - in zero tolerance for pivot test If a the absolute value of a pivot is <= zero_tolerance, then the pivoit is assumed to be zero. pt_dim - [in] dimension of points pt_stride - [in] stride between points (>=pt_dim) pt - [in/out] array of m_row_count*pt_stride values. The i-th point is (pt[i*pt_stride],...,pt[i*pt_stride+pt_dim-1]). This array of points is row reduced along with the matrix. pivot - [out] If not nullptr, then the value of the smallest pivot is returned here Returns: Rank of the matrix. Remarks: The matrix itself is row reduced so that the result is an upper triangular matrix with 1's on the diagonal. See Also: ON_Matrix::BackSolve

◆ RowReduce() [4/4]

int ON_Matrix::RowReduce ( double  ,
ON_3dPoint ,
double *  = nullptr 
)

Description: Row reduce a matrix as the first step in solving M*X=B where B is a column of 3d points Parameters: zero_tolerance - in zero tolerance for pivot test If the absolute value of a pivot is <= zero_tolerance, then the pivot is assumed to be zero. B - [in/out] an array of m_row_count 3d points that is row reduced with the matrix. determinant - [out] value of determinant is returned here. pivot - [out] If not nullptr, then the value of the smallest pivot is returned here Returns: Rank of the matrix. Remarks: The matrix itself is row reduced so that the result is an upper triangular matrix with 1's on the diagonal. See Also: ON_Matrix::BackSolve

◆ RowScale()

void ON_Matrix::RowScale ( int  ,
double   
)

◆ Scale()

bool ON_Matrix::Scale ( double  s)

Description: Set this = s*this. Parameters: s - [in] Returns: True when A and s are valid.

◆ SetDiagonal() [1/4]

void ON_Matrix::SetDiagonal ( const double *  )

sets diagonal values and zeros off diagonal values

◆ SetDiagonal() [2/4]

void ON_Matrix::SetDiagonal ( const ON_SimpleArray< double > &  )

sets size to length X lengthdiagonal values and zeros off diagonal values

◆ SetDiagonal() [3/4]

void ON_Matrix::SetDiagonal ( double  )

sets diagonal value and zeros off diagonal values

◆ SetDiagonal() [4/4]

void ON_Matrix::SetDiagonal ( int  ,
const double *   
)

sets size to count x count and diagonal values and zeros off diagonal values

◆ SwapCols()

bool ON_Matrix::SwapCols ( int  ,
int   
)

ints are col indices to swap

◆ SwapRows()

bool ON_Matrix::SwapRows ( int  ,
int   
)

ints are row indices to swap

◆ Transpose()

bool ON_Matrix::Transpose ( )

◆ UnsignedColCount()

unsigned int ON_Matrix::UnsignedColCount ( ) const

◆ UnsignedMaxCount()

unsigned int ON_Matrix::UnsignedMaxCount ( ) const

largest of row and column count

◆ UnsignedMinCount()

unsigned int ON_Matrix::UnsignedMinCount ( ) const

smallest of row and column count

◆ UnsignedRowCount()

unsigned int ON_Matrix::UnsignedRowCount ( ) const

◆ Zero()

void ON_Matrix::Zero ( )

Member Data Documentation

◆ m

double** ON_Matrix::m = nullptr

m[i][j] = value at row i and column j