Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
Loading...
Searching...
No Matches
matrix3.c
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025-2026 Igal Alkon
2// SPDX-FileCopyrightText: 2026 ALKONTEK <git@alkontek.com>
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <vecmat.h>
6
15{
16 matrix3 m;
18 return m;
19}
20
31{
32 matrix3 res;
33 mat3_mul_ptr(&res, &a, &b);
34 return res;
35}
36
46{
47 matrix3 res;
48 mat3_transpose_ptr(&res, &m);
49 return res;
50}
51
61{
62 matrix3 res;
63 mat3_inverse_ptr(&res, &m);
64 return res;
65}
66
76{
77 matrix3 m;
78 mat3_rotation_z_ptr(&m, degrees);
79 return m;
80}
81
89{
90 return m.v[0] * (m.v[4] * m.v[8] - m.v[5] * m.v[7]) -
91 m.v[1] * (m.v[3] * m.v[8] - m.v[5] * m.v[6]) +
92 m.v[2] * (m.v[3] * m.v[7] - m.v[4] * m.v[6]);
93}
94
105{
106 vector3 res;
107 mat3_mul_vec3_ptr(&res, &m, &v);
108 return res;
109}
110
121{
122 vector2 res;
123 mat3_mul_vec2_ptr(&res, &m, &v);
124 return res;
125}
126
136{
137 matrix3 res;
138 mat3_rotation_x_ptr(&res, degrees);
139 return res;
140}
141
151{
152 matrix3 res;
153 mat3_rotation_y_ptr(&res, degrees);
154 return res;
155}
156
166{
167 matrix3 res;
168 mat3_translate_ptr(&res, &t);
169 return res;
170}
171
181{
182 matrix3 res;
183 mat3_scale_ptr(&res, &s);
184 return res;
185}
186
196{
197 matrix3 res;
198 mat3_from_mat4_ptr(&res, &m);
199 return res;
200}
matrix3 mat3_rotation_y(const vm_float_t degrees)
Builds a 3x3 rotation matrix around the Y axis (degrees).
Definition matrix3.c:150
matrix3 mat3_rotation_x(const vm_float_t degrees)
Builds a 3x3 rotation matrix around the X axis (degrees).
Definition matrix3.c:135
matrix3 mat3_identity(void)
Constructs the 3x3 identity matrix.
Definition matrix3.c:14
matrix3 mat3_rotation_z(const vm_float_t degrees)
Constructs the 3x3 rotation matrix around the Z-axis.
Definition matrix3.c:75
vector3 mat3_mul_vec3(const matrix3 m, const vector3 v)
Multiplies a 3x3 matrix by a vector3.
Definition matrix3.c:104
matrix3 mat3_scale(const vector2 s)
Builds a 3x3 2D scaling matrix.
Definition matrix3.c:180
matrix3 mat3_translate(const vector2 t)
Builds a 3x3 2D translation matrix.
Definition matrix3.c:165
matrix3 mat3_transpose(const matrix3 m)
Computes the transpose of a 3x3 matrix.
Definition matrix3.c:45
vm_float_t mat3_determinant(const matrix3 m)
Computes the determinant of a 3x3 matrix.
Definition matrix3.c:88
matrix3 mat3_mul(const matrix3 a, const matrix3 b)
Multiplies two 3x3 matrices.
Definition matrix3.c:30
matrix3 mat3_from_mat4(const matrix4 m)
Copies the upper-left 3x3 of a matrix4.
Definition matrix3.c:195
matrix3 mat3_inverse(const matrix3 m)
Computes the inverse of a 3x3 matrix.
Definition matrix3.c:60
vector2 mat3_mul_vec2(const matrix3 m, const vector2 v)
Applies a 3x3 affine transform to a vector2.
Definition matrix3.c:120
vm_float_t v[VECMAT_MAT3_SIZE]
Definition vecmat.h:238
void mat3_identity_ptr(matrix3 *res)
Initializes the 3x3 matrix to identity (diagonal 1.0, others 0.0).
Definition matrix3_ptr.c:12
void mat3_mul_vec2_ptr(vector2 *res, const matrix3 *m, const vector2 *v)
Applies a 3x3 affine transform to a vector2.
void mat3_translate_ptr(matrix3 *res, const vector2 *t)
Builds a 3x3 2D translation matrix.
void mat3_from_mat4_ptr(matrix3 *res, const matrix4 *m)
Copies the upper-left 3x3 of a matrix4.
void mat3_inverse_ptr(matrix3 *res, const matrix3 *m)
Computes the inverse of the input 3x3 matrix using the adjugate method and stores in res.
Definition matrix3_ptr.c:78
void mat3_mul_ptr(matrix3 *res, const matrix3 *a, const matrix3 *b)
Multiplies two 3x3 matrices (a * b) in column-major / column-vector convention.
Definition matrix3_ptr.c:34
void mat3_mul_vec3_ptr(vector3 *res, const matrix3 *m, const vector3 *v)
Multiplies a 3x3 matrix by a vector3.
void mat3_scale_ptr(matrix3 *res, const vector2 *s)
Builds a 3x3 2D scaling matrix.
double vm_float_t
Definition vecmat.h:79
void mat3_transpose_ptr(matrix3 *res, const matrix3 *m)
Computes the transpose of the input 3x3 matrix and stores in res.
Definition matrix3_ptr.c:58
void mat3_rotation_x_ptr(matrix3 *res, vm_float_t degrees)
Builds a 3x3 rotation matrix around the X axis (degrees).
void mat3_rotation_z_ptr(matrix3 *res, vm_float_t degrees)
Sets the 3x3 matrix to a rotation around the Z-axis by the given angle in degrees.
void mat3_rotation_y_ptr(matrix3 *res, vm_float_t degrees)
Builds a 3x3 rotation matrix around the Y axis (degrees).