C# Class GeometryClassLibrary.Matrix

ファイルを表示 Open project: ParagonTruss/GeometryClassLibrary Class Usage Examples

Public Methods

Method Description
AbsoluteValue ( ) : Matrix

Returns a matrix that is this matrix with the absolute value function applied to each element

AddTo ( Matrix passedMatrix ) : Matrix

Returns the sum of this matrix and the passed matrix

AddToAt ( int row, int col, Matrix matrix ) : void

Adds the passed matrix to the larger matrix starting at the specified row,col entry.

As1DArray ( EnumerationOrder order = EnumerationOrder.ByRow ) : double[]
CanBeAddedTo ( Matrix passedMatrix ) : bool

Checks to see if this matrix and the passed matrix can be added together. In order to be able to add two matrices, they must have the same Distances.

CanBeMultipliedBy ( Matrix passedMatrix ) : bool

Checks to see if this matrix can be multiplied by the passed matrix IN THAT ORDER. In order to multiply two matrices, the number of columns in the first matrix must equal the number of rows in the second matrix.

Columns ( ) : List
ConvertRotationMatrixToQuaternion ( ) : Matrix

Converts the given rotation Matrix into a Quaternion, which also represents orientation but in a more mathematically unique way since only two quaternions represent the same orientation, and they have the following relation to each other: q = -q

Decompose ( int &permutationArray, int &toggle ) : Matrix

Performs Doolittle decomposition with partial pivoting and returns a combined LU matrix

Determinant ( ) : double

Computes the determinant of a matrix

Equals ( object obj ) : bool

Does the same thing as == if the passed-in object is an identical matrix

EulerAngles ( ) : List

Returns the euler angles (for rotations in x, y,z order) assuming the upper left 3x3 submatrix is a rotation matrix.

ExtractLower ( ) : Matrix

Returns Matrix with only the values in the lower triangle (below main diagonal) intact. Puts 1.0's on diagonal and 0.0's in upper triangle

ExtractUpper ( ) : Matrix

Returns Matrix with only the values in the main diagonal and upper triangle (above main diagonal) intact. Has 0.0's in lower triangle

GenerateCofactorMatrix ( ) : Matrix

Creates the cofactor matrix corresponding to this matrix

GetCofactor ( int rowIndex, int columnIndex ) : double

Returns the cofactor for the specified element of a square matrix

GetColumn ( int passedColumnIndex ) : double[]

Returns the specified column of the matrix

GetElement ( int rowIndex, int columnIndex ) : double

Returns the element at row "rowIndex" and column "columnIndex"

GetHashCode ( ) : int
GetPseudoInverse ( double a ) : ].double[
GetRow ( int passedrowIndex ) : double[]

Returns the specified row of the matrix

GetSubMatrix ( int indexOfRowToLeaveOut, int indexOfColumnToLeaveOut ) : Matrix

Returns a matrix with the specified row and column removed

IdentityMatrix ( int passedNumberOfRowsAndColumns ) : Matrix

Returns an Identity Matrix of the specified size. That is, a square matrix with 1's on the diagonal and 0's everywhere else.

InsertMatrixAt ( Matrix passedMatrix, int destinationRow, int destinationColumn ) : Matrix

Inserts the passed Matrix into this Matrix starting at the specified index

Invert ( ) : Matrix

Returns the inverse of this matrix

IsAllZeros ( ) : bool

Returns true if every element in this matrix is zero, false otherwise

IsInvertible ( ) : bool

Returns true if this matrix has an inverse, false otherwise

IsSquare ( ) : bool

Checks to see if this matrix is square

LUDecomp ( double a, double &lower, double &upper ) : void
LUSolve ( double l, double u, double b ) : double[]
Matrix ( Matrix passedMatrix ) : System

Makes a copy of the passed matrix

Matrix ( double array ) : System

Creates a matrix with a single column from the array.

Matrix ( double array, int numRows, int numCols, EnumerationOrder order = EnumerationOrder.ByColumn ) : System

Construct a matrix from a 1 Dimensional array either building row by row, or column by column.

Matrix ( int numRowsAndColumns ) : System

Creates a square matrix with the passed number of rows and columns

Matrix ( int numRows, int numCols ) : System

Creates a matrix of the desired number of rows and columns, with all entries initialized to zero.

MultiplyBy ( Matrix passedMatrix ) : Matrix

Returns the product matrix of this matrix multiplied by the passed matrix, in that order.

NullSpace ( ) : List
PointAsProjectiveColumnVector ( Point point ) : Matrix
ProjectiveMatrixToRotationMatrix ( Matrix matrix ) : Matrix
PseudoInvSolve ( double p, double b ) : double[]
RemoveColumn ( int columnIndexToDelete ) : Matrix

Returns a matrix with the specified column removed

RemoveColumns ( int passedIndicesOfColumnsToRemove ) : Matrix

Returns a new matrix with all of the specified columns removed

RemoveRow ( int rowIndexToDelete ) : Matrix

Returns a matrix with the specified row removed

RemoveRows ( int passedIndicesOfRowsToRemove ) : Matrix

Returns a new matrix with all of the specified rows removed

RotationMatrixAboutOrigin ( Rotation passedRotation ) : Matrix

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the passed axis line by the specified angle

RotationMatrixAboutX ( System.Angle rotationAngle ) : Matrix

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the X axis by the specified angle

RotationMatrixAboutY ( System.Angle rotationAngle ) : Matrix

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the Y axis by the specified angle

RotationMatrixAboutZ ( System.Angle rotationAngle ) : Matrix

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the Z axis by the specified angle

Rows ( ) : List
SetColumn ( int passedColumnIndex, double passedColumn ) : void

Replaces the specified column of the matrix with the passed column

SetElement ( int rowIndex, int columnIndex, double element ) : void

SetRow ( int passedrowIndex, double passedRow ) : void

Replaces the specified row of the matrix with the passed row

ShiftPoint ( Point point, Matrix matrix ) : Point
SolveMatrix ( double augmentedMatrix ) : double[]

Turns an augmented matrix into Reduced Row Echelon form, by modifying the matrix in place. Then returns the last column.

SystemSolve ( Matrix columnMatrix ) : Matrix

Solves for the column matrix x, where Ax = b.

ToString ( ) : string
Transpose ( ) : Matrix

Returns the transpose of a given matrix. The transpose is found by swapping the rows and columns (i.e. reflecting all the elements across the main diagonal)

operator ( ) : Matrix

Returns the sum of 2 matrices of equal size

operator ( ) : bool

Not a perfect equality operator, is only accurate up to difference of 0.00000001 in any two elements

this ( int i ) : double

For setting and accessing column vectors

this ( int i, int j ) : double

Private Methods

Method Description
Matrix ( ) : System

Private constructor for the benefit of data frameworks like Entity Framework and Json.NET

Matrix ( Matrix passedMatrix ) : System

Makes a copy of the passed matrix

_enumerateByColumn ( ) : double[]
_enumerateByRow ( ) : double[]
_pointFromProjectiveColumnVector ( Matrix projectiveVector ) : Point
_vectorOfDoublesToVectorOfInches ( Vector vector ) : Vector

Method Details

AbsoluteValue() public method

Returns a matrix that is this matrix with the absolute value function applied to each element
public AbsoluteValue ( ) : Matrix
return Matrix

AddTo() public method

Returns the sum of this matrix and the passed matrix
public AddTo ( Matrix passedMatrix ) : Matrix
passedMatrix Matrix
return Matrix

AddToAt() public method

Adds the passed matrix to the larger matrix starting at the specified row,col entry.
public AddToAt ( int row, int col, Matrix matrix ) : void
row int
col int
matrix Matrix
return void

As1DArray() public method

public As1DArray ( EnumerationOrder order = EnumerationOrder.ByRow ) : double[]
order EnumerationOrder
return double[]

CanBeAddedTo() public method

Checks to see if this matrix and the passed matrix can be added together. In order to be able to add two matrices, they must have the same Distances.
public CanBeAddedTo ( Matrix passedMatrix ) : bool
passedMatrix Matrix
return bool

CanBeMultipliedBy() public method

Checks to see if this matrix can be multiplied by the passed matrix IN THAT ORDER. In order to multiply two matrices, the number of columns in the first matrix must equal the number of rows in the second matrix.
public CanBeMultipliedBy ( Matrix passedMatrix ) : bool
passedMatrix Matrix
return bool

Columns() public method

public Columns ( ) : List
return List

ConvertRotationMatrixToQuaternion() public method

Converts the given rotation Matrix into a Quaternion, which also represents orientation but in a more mathematically unique way since only two quaternions represent the same orientation, and they have the following relation to each other: q = -q
public ConvertRotationMatrixToQuaternion ( ) : Matrix
return Matrix

Decompose() public method

Performs Doolittle decomposition with partial pivoting and returns a combined LU matrix
public Decompose ( int &permutationArray, int &toggle ) : Matrix
permutationArray int Keeps track of how the matrices have been rearranged during the calculation
toggle int is +1 or -1 (even or odd)
return Matrix

Determinant() public method

Computes the determinant of a matrix
public Determinant ( ) : double
return double

Equals() public method

Does the same thing as == if the passed-in object is an identical matrix
public Equals ( object obj ) : bool
obj object
return bool

EulerAngles() public method

Returns the euler angles (for rotations in x, y,z order) assuming the upper left 3x3 submatrix is a rotation matrix.
public EulerAngles ( ) : List
return List

ExtractLower() public method

Returns Matrix with only the values in the lower triangle (below main diagonal) intact. Puts 1.0's on diagonal and 0.0's in upper triangle
public ExtractLower ( ) : Matrix
return Matrix

ExtractUpper() public method

Returns Matrix with only the values in the main diagonal and upper triangle (above main diagonal) intact. Has 0.0's in lower triangle
public ExtractUpper ( ) : Matrix
return Matrix

GenerateCofactorMatrix() public method

Creates the cofactor matrix corresponding to this matrix
public GenerateCofactorMatrix ( ) : Matrix
return Matrix

GetCofactor() public method

Returns the cofactor for the specified element of a square matrix
public GetCofactor ( int rowIndex, int columnIndex ) : double
rowIndex int
columnIndex int
return double

GetColumn() public method

Returns the specified column of the matrix
public GetColumn ( int passedColumnIndex ) : double[]
passedColumnIndex int
return double[]

GetElement() public method

Returns the element at row "rowIndex" and column "columnIndex"
public GetElement ( int rowIndex, int columnIndex ) : double
rowIndex int The row number of the desired element
columnIndex int The column number of the desired element
return double

GetHashCode() public method

public GetHashCode ( ) : int
return int

GetPseudoInverse() public static method

public static GetPseudoInverse ( double a ) : ].double[
a double
return ].double[

GetRow() public method

Returns the specified row of the matrix
public GetRow ( int passedrowIndex ) : double[]
passedrowIndex int
return double[]

GetSubMatrix() public method

Returns a matrix with the specified row and column removed
public GetSubMatrix ( int indexOfRowToLeaveOut, int indexOfColumnToLeaveOut ) : Matrix
indexOfRowToLeaveOut int
indexOfColumnToLeaveOut int
return Matrix

IdentityMatrix() public static method

Returns an Identity Matrix of the specified size. That is, a square matrix with 1's on the diagonal and 0's everywhere else.
public static IdentityMatrix ( int passedNumberOfRowsAndColumns ) : Matrix
passedNumberOfRowsAndColumns int
return Matrix

InsertMatrixAt() public method

Inserts the passed Matrix into this Matrix starting at the specified index
public InsertMatrixAt ( Matrix passedMatrix, int destinationRow, int destinationColumn ) : Matrix
passedMatrix Matrix
destinationRow int
destinationColumn int
return Matrix

Invert() public method

Returns the inverse of this matrix
public Invert ( ) : Matrix
return Matrix

IsAllZeros() public method

Returns true if every element in this matrix is zero, false otherwise
public IsAllZeros ( ) : bool
return bool

IsInvertible() public method

Returns true if this matrix has an inverse, false otherwise
public IsInvertible ( ) : bool
return bool

IsSquare() public method

Checks to see if this matrix is square
public IsSquare ( ) : bool
return bool

LUDecomp() public static method

public static LUDecomp ( double a, double &lower, double &upper ) : void
a double
lower double
upper double
return void

LUSolve() public static method

public static LUSolve ( double l, double u, double b ) : double[]
l double
u double
b double
return double[]

Matrix() public method

Makes a copy of the passed matrix
public Matrix ( Matrix passedMatrix ) : System
passedMatrix Matrix
return System

Matrix() public method

Creates a matrix with a single column from the array.
public Matrix ( double array ) : System
array double
return System

Matrix() public method

Construct a matrix from a 1 Dimensional array either building row by row, or column by column.
public Matrix ( double array, int numRows, int numCols, EnumerationOrder order = EnumerationOrder.ByColumn ) : System
array double
numRows int
numCols int
order EnumerationOrder
return System

Matrix() public method

Creates a square matrix with the passed number of rows and columns
public Matrix ( int numRowsAndColumns ) : System
numRowsAndColumns int
return System

Matrix() public method

Creates a matrix of the desired number of rows and columns, with all entries initialized to zero.
public Matrix ( int numRows, int numCols ) : System
numRows int
numCols int
return System

MultiplyBy() public method

Returns the product matrix of this matrix multiplied by the passed matrix, in that order.
public MultiplyBy ( Matrix passedMatrix ) : Matrix
passedMatrix Matrix
return Matrix

NullSpace() public method

public NullSpace ( ) : List
return List

PointAsProjectiveColumnVector() public static method

public static PointAsProjectiveColumnVector ( Point point ) : Matrix
point Point
return Matrix

ProjectiveMatrixToRotationMatrix() public static method

public static ProjectiveMatrixToRotationMatrix ( Matrix matrix ) : Matrix
matrix Matrix
return Matrix

PseudoInvSolve() public static method

public static PseudoInvSolve ( double p, double b ) : double[]
p double
b double
return double[]

RemoveColumn() public method

Returns a matrix with the specified column removed
public RemoveColumn ( int columnIndexToDelete ) : Matrix
columnIndexToDelete int
return Matrix

RemoveColumns() public method

Returns a new matrix with all of the specified columns removed
public RemoveColumns ( int passedIndicesOfColumnsToRemove ) : Matrix
passedIndicesOfColumnsToRemove int
return Matrix

RemoveRow() public method

Returns a matrix with the specified row removed
public RemoveRow ( int rowIndexToDelete ) : Matrix
rowIndexToDelete int
return Matrix

RemoveRows() public method

Returns a new matrix with all of the specified rows removed
public RemoveRows ( int passedIndicesOfRowsToRemove ) : Matrix
passedIndicesOfRowsToRemove int
return Matrix

RotationMatrixAboutOrigin() public static method

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the passed axis line by the specified angle
public static RotationMatrixAboutOrigin ( Rotation passedRotation ) : Matrix
passedRotation Rotation
return Matrix

RotationMatrixAboutX() public static method

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the X axis by the specified angle
public static RotationMatrixAboutX ( System.Angle rotationAngle ) : Matrix
rotationAngle System.Angle
return Matrix

RotationMatrixAboutY() public static method

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the Y axis by the specified angle
public static RotationMatrixAboutY ( System.Angle rotationAngle ) : Matrix
rotationAngle System.Angle
return Matrix

RotationMatrixAboutZ() public static method

Returns a matrix that can be multiplied by another matrix to represent a rotation of that matrix about the Z axis by the specified angle
public static RotationMatrixAboutZ ( System.Angle rotationAngle ) : Matrix
rotationAngle System.Angle
return Matrix

Rows() public method

public Rows ( ) : List
return List

SetColumn() public method

Replaces the specified column of the matrix with the passed column
public SetColumn ( int passedColumnIndex, double passedColumn ) : void
passedColumnIndex int
passedColumn double
return void

SetElement() public method

public SetElement ( int rowIndex, int columnIndex, double element ) : void
rowIndex int The number of the row where the element will be added
columnIndex int The number of the column where the element will be added
element double
return void

SetRow() public method

Replaces the specified row of the matrix with the passed row
public SetRow ( int passedrowIndex, double passedRow ) : void
passedrowIndex int
passedRow double
return void

ShiftPoint() public static method

public static ShiftPoint ( Point point, Matrix matrix ) : Point
point Point
matrix Matrix
return Point

SolveMatrix() public static method

Turns an augmented matrix into Reduced Row Echelon form, by modifying the matrix in place. Then returns the last column.
public static SolveMatrix ( double augmentedMatrix ) : double[]
augmentedMatrix double
return double[]

SystemSolve() public method

Solves for the column matrix x, where Ax = b.
public SystemSolve ( Matrix columnMatrix ) : Matrix
columnMatrix Matrix
return Matrix

ToString() public method

public ToString ( ) : string
return string

Transpose() public method

Returns the transpose of a given matrix. The transpose is found by swapping the rows and columns (i.e. reflecting all the elements across the main diagonal)
public Transpose ( ) : Matrix
return Matrix

operator() public static method

Returns the sum of 2 matrices of equal size
public static operator ( ) : Matrix
return Matrix

operator() public static method

Not a perfect equality operator, is only accurate up to difference of 0.00000001 in any two elements
public static operator ( ) : bool
return bool

this() public method

For setting and accessing column vectors
public this ( int i ) : double
i int
return double

this() public method

public this ( int i, int j ) : double
i int
j int
return double