Browse
Code
for
All Platforms
in
All Categories
sorted by
Popular
• More ...
• More ...
• More ...
• More ...
• More ...
• More ...
• More ...
• More ...
• More ...
• More ...

# Fast 2x2 Matrix class

Released 4 years ago , Last update 4 years ago

This class handles common operations for 2x2 square matrices. Useful for 2D graphics calculations for side-scrollers, 2D game engines and similar bi-dimensional games. The Matrix class also implements advanced mathematical functions optimized to be executed in the fastes way possible

2D vector and matrix calculations are very common in bi-dimensional games and are used in side-scrollers, isometric games, 2D game engines and similar needs.

Common operations are implemented through the use of templated overloaded operators, allowing for very readable and fast 2D matrix calculations.

This class is compiler-agnostic, and can be used on multiple platforms (including mobile) with minimal refactoring.

### Usage examples

Declare a matrix using :

``````CMatrix2x2f Ma;

Ma.Set (  1 ,2 ,  3 ,4 );

Mb.Set (  4 ,5 ,  6 ,7 );

Mc.Set (  1 ,2 ,  2 ,1 );``````

Common operations :

``````// multiplication

Ma=Ma * 2.0f ;

Ma*= 2.0f ;

Ma = Mb * 3.0f;

Ma = 3.0f * Mb ;

Ma = Mb / 2.0f ; // multipication by inverse of a constant

// sum and subtraction

Ma+=Mb;

Ma-=Mb;

Ma = Mb + Mc;

Ma = -Mb + Mc;

// matrix multilication

Ma = Mb * Mc ;

Ma= 4.0f / Mb;

Invert(Ma);     //invert matrix

Transpose(Ma);      //transpose matrix

Zero(Ma);               // zero out the matrix

Identity(Ma);               // identity matrix

Ma.Get(1,0);            // gets value at coordinates

Ma[0]=2.0f;         // setting a value by direct access

// logic operations

if ( Ma!=Mb )     cout << "Matrices are different" << endl;

if ( Ma==Mb )   cout << "Matrices are equal" << endl;

Rot ( Ma,45.0f );       // compute matrix rotation

GetRank(Ma);                   // gets matrix rank

float d = Ma.Determinant();   // gets determinant

// compute the trace of the matrix``````

float t= GetMatrixTrace( Ma );

// Determine if the matrix is lower triangular

bool b=IsLowerTriangular (Ma);

// Determine if the matrix is upper triangular

bool b=IsUpperTriangular (Ma);

// Determine if the matrix is skew-symmetric

bool b=IsSkewSimmetric(Ma) ;

// test if matrix is simmetric

bool b=IsSimmetric(Ma);

// Determine if the matrix is diagonal

bool b=IsDiagonal (Ma) ;

// calculate the condition number // which is the norm multiplied // byt the norm of the matrix // inverse

float c=ConditionNumber(Ma);

// calculate the norm of a matrix

float n=Norm (Ma);

// Determine if the matrix is singular

bool b=Ma.IsSingular (Ma) ;

// solve the system defined by the matrix

SolveLinearMatrix( Ma,V,S );

## Pricing

### 14-day money-back guarantee

#### Personal use only

• 1 application

• Can distribute binary products only

• Non-commercial use

2 licenses, starting from From » \$4.99

## Get A Quote

What do you need?
• Custom development
• Integration
• Customization / Reskinning
• Consultation
When do you need it?
• Soon
• Next week
• Next month
• Anytime

### Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.

Or enter your name and Email
No comments have been posted yet.