Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
Loading...
Searching...
No Matches
matrix2.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 matrix2 res;
18 return res;
19}
20
31{
32 matrix2 res;
33 mat2_mul_ptr(&res, &a, &b);
34 return res;
35}
36
46{
47 matrix2 res;
48 mat2_transpose_ptr(&res, &m);
49 return res;
50}
51
61{
62 matrix2 res;
63 mat2_inverse_ptr(&res, &m);
64 return res;
65}
66
76{
77 matrix2 res;
78 mat2_rotation_z_ptr(&res, degrees);
79 return res;
80}
81
89{
90 return m.v[0] * m.v[3] - m.v[1] * m.v[2];
91}
92
103{
104 vector2 res;
105 mat2_mul_vec2_ptr(&res, &m, &v);
106 return res;
107}
108
118{
119 matrix2 res;
120 mat2_scale_ptr(&res, &s);
121 return res;
122}
123
133{
134 matrix2 res;
135 mat2_from_mat3_ptr(&res, &m);
136 return res;
137}
matrix2 mat2_transpose(const matrix2 m)
Computes the transpose of a 2x2 matrix.
Definition matrix2.c:45
matrix2 mat2_inverse(const matrix2 m)
Computes the inverse of a 2x2 matrix.
Definition matrix2.c:60
vm_float_t mat2_determinant(const matrix2 m)
Calculates the determinant of the given 2x2 matrix.
Definition matrix2.c:88
matrix2 mat2_identity(void)
Constructs the 2x2 identity matrix.
Definition matrix2.c:14
vector2 mat2_mul_vec2(const matrix2 m, const vector2 v)
Multiplies a 2x2 matrix by a vector2.
Definition matrix2.c:102
matrix2 mat2_from_mat3(const matrix3 m)
Copies the upper-left 2x2 of a matrix3.
Definition matrix2.c:132
matrix2 mat2_scale(const vector2 s)
Builds a 2x2 scaling matrix from a vector2.
Definition matrix2.c:117
matrix2 mat2_mul(const matrix2 a, const matrix2 b)
Multiplies two 2x2 matrices (a * b).
Definition matrix2.c:30
matrix2 mat2_rotation_z(const vm_float_t degrees)
Constructs a 2x2 Z-axis rotation matrix.
Definition matrix2.c:75
vm_float_t v[VECMAT_MAT2_SIZE]
Definition vecmat.h:213
void mat2_scale_ptr(matrix2 *res, const vector2 *s)
Builds a 2x2 scaling matrix from a vector2.
void mat2_mul_ptr(matrix2 *res, const matrix2 *a, const matrix2 *b)
Multiplies two 2x2 matrices (a * b) in column-major / column-vector convention.
Definition matrix2_ptr.c:26
void mat2_transpose_ptr(matrix2 *res, const matrix2 *m)
Computes the transpose of the input 2x2 matrix and stores in res.
Definition matrix2_ptr.c:43
void mat2_rotation_z_ptr(matrix2 *res, vm_float_t degrees)
Sets res to a 2x2 rotation matrix for rotation around the Z-axis.
Definition matrix2_ptr.c:97
void mat2_identity_ptr(matrix2 *res)
Initializes the 2x2 matrix to identity (diagonal 1.0, others 0.0).
Definition matrix2_ptr.c:12
void mat2_inverse_ptr(matrix2 *res, const matrix2 *m)
Computes the inverse of the input 2x2 matrix using determinant and stores in res.
Definition matrix2_ptr.c:60
double vm_float_t
Definition vecmat.h:79
void mat2_mul_vec2_ptr(vector2 *res, const matrix2 *m, const vector2 *v)
Multiplies a 2x2 matrix by a vector2.
Definition matrix2_ptr.c:81
void mat2_from_mat3_ptr(matrix2 *res, const matrix3 *m)
Copies the upper-left 2x2 of a matrix3.