Add some more mat3 functions
This commit is contained in:
parent
55ba9f6cde
commit
7e5de6f6eb
3 changed files with 108 additions and 0 deletions
|
|
@ -62,4 +62,42 @@ static inline struct Mat3 mat3_add(struct Mat3 a, struct Mat3 b) {
|
|||
return (struct Mat3){r1, r2, r3};
|
||||
}
|
||||
|
||||
static inline struct Mat3 mat3_sub(struct Mat3 a, struct Mat3 b) {
|
||||
struct Vec3 r1 = vec3_sub(a.r1, b.r1);
|
||||
struct Vec3 r2 = vec3_sub(a.r2, b.r2);
|
||||
struct Vec3 r3 = vec3_sub(a.r3, b.r3);
|
||||
|
||||
return (struct Mat3){r1, r2, r3};
|
||||
}
|
||||
|
||||
static inline struct Mat3 mat3_mul(struct Mat3 a, struct Mat3 b) {
|
||||
struct Vec3 r1 = {
|
||||
a.r1.x * b.r1.x + a.r1.y * b.r2.x + a.r1.z * b.r3.x,
|
||||
a.r1.x * b.r1.y + a.r1.y * b.r2.y + a.r1.z * b.r3.y,
|
||||
a.r1.x * b.r1.z + a.r1.y * b.r2.z + a.r1.z * b.r3.z,
|
||||
};
|
||||
|
||||
struct Vec3 r2 = {
|
||||
a.r2.x * b.r1.x + a.r2.y * b.r2.x + a.r2.z * b.r3.x,
|
||||
a.r2.x * b.r1.y + a.r2.y * b.r2.y + a.r2.z * b.r3.y,
|
||||
a.r2.x * b.r1.z + a.r2.y * b.r2.z + a.r2.z * b.r3.z,
|
||||
};
|
||||
|
||||
struct Vec3 r3 = {
|
||||
a.r3.x * b.r1.x + a.r3.y * b.r2.x + a.r3.z * b.r3.x,
|
||||
a.r3.x * b.r1.y + a.r3.y * b.r2.y + a.r3.z * b.r3.y,
|
||||
a.r3.x * b.r1.z + a.r3.y * b.r2.z + a.r3.z * b.r3.z,
|
||||
};
|
||||
|
||||
return (struct Mat3){r1, r2, r3};
|
||||
}
|
||||
|
||||
static inline double mat3_det(struct Mat3 a) {
|
||||
return a.r1.x * (a.r2.y * a.r3.z - a.r2.z * a.r3.y) -
|
||||
a.r1.y * (a.r2.x * a.r3.z - a.r2.z * a.r3.x) +
|
||||
a.r1.z * (a.r2.x * a.r3.y - a.r2.y * a.r3.x);
|
||||
}
|
||||
|
||||
struct Mat3 mat3_inv(struct Mat3 a);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue