# Asset - ExtensionGMLinear: Easy matrix and vector operations for GMS 2.x and 1.4

#### FrostyCat

##### Member
GMLinear
Easy matrix and vector operations for GMS 2.x and 1.4

Overview
GMLinear is an implementation of matrix and vector operations in pure GML. You can use it to simplify many common calculations in 2D and 3D geometry and implement algorithms/formulas involving linear algebra.

Features
• Easy to use, intuitive constructors for building vectors and matrices quickly
• Vector operations: Addition, subtraction, dot product, cross product, scalar-vector product, norms, distances, unit vectors, linear interpolation, projection/rejection, coordinate system conversions
• Matrix operations: Addition, subtraction, scalar-matrix product, matrix-matrix product, matrix-vector product, transpose, inverse
• Hard-coded optimized functions available for 2D, 3D and 4D vectors and 2x2, 3x3 and 4x4 matrices

GMS 2.x: YoYo Marketplace | GitHub | Documentation

Example

Find the intersection point between the plane containing the point (0, 0, 1) with a normal of (1, 0, 0), and the line containing the point (4, 9, -4) and pointing in the direction (-1, 3, 0.5). (see: Line-plane intersection)

With GMLinear:
Code:
``````p_0 = r3(0, 0, 1);
n = r3(1, 0, 0);
l_0 = r3(4, 9, -4);
l = r3(-1, 3, 0.5);
d = r3_dot(r3_subtract(p_0, l_0), n)/r3_dot(l, n);
show_message("Intersection point is: (" + r3_encode_string(intersection) + ")");``````
Without GMLinear:
Code:
``````p_0x = 0;
p_0y = 0;
p_0z = 1;
nx = 1;
ny = 0;
nz = 0;
l_0x = 4;
l_0y = 9;
l_0z = -4;
lx = -1;
ly = 3;
lz = 0.5;
d = (((p_0x-l_0x)*nx)+((p_0y-l_0y)*ny)+((p_0z-l_0z)*nz))/(lx*nx+ly*ny+lz*nz);
intersectionx = l_0x+d*lx;
intersectiony = l_0y+d*ly;
intersectionz = l_0z+d*lz;
show_message("Intersection point is: (" + string(intersectionx) + ", " + string(intersectiony) + ", " + string(intersectionz) + ")");``````

Feedback Welcome!
If you have any suggestions for new constructors/use cases or bug reports, please open an issue or contribute on GitHub.

#### Walky

##### Member
Nice, thanks for sharing this.

#### BCrash

##### Member
This will come in handy. Thanks for sharing!