6 typedef struct mat3x3 {
11 mat3x3 make_mat3x3(float a11, float a12, float a13,
12 float a21, float a22, float a23,
13 float a31, float a32, float a33)
27 mat3x3 mat3x3_product(mat3x3 m1, mat3x3 m2)
31 for (int i = 0; i < 3; ++i) {
32 for (int j = 0; j < 3; ++j) {
34 for (int k = 0; k < 3; ++k) {
35 result.M[i][j] += m1.M[i][k] * m2.M[k][j];
44 mat3x3 mat3x3_product2(mat3x3 m1, mat3x3 m2, mat3x3 m3)
46 return mat3x3_product(m1, mat3x3_product(m2, m3));
50 mat3x3 trans_mat(float x, float y)
64 mat3x3 trans_mat_vec(Vec v)
66 return trans_mat(v.x, v.y);
70 mat3x3 rot_mat(float angle)
74 {cosf(angle), -sinf(angle), 0.0f},
75 {sinf(angle), cosf(angle), 0.0f},
84 mat3x3 scale_mat(float factor)
98 Point point_mat3x3_product(Point p, mat3x3 m)
100 /* Convert p to Homogeneous coordinates */
101 const float homo_p[3] = {p.x, p.y, 1};
103 /* Transform p with matrix m */
104 const float trans_p[3] = {
105 homo_p[0] * m.M[0][0] + homo_p[1] * m.M[0][1] + homo_p[2] * m.M[0][2],
106 homo_p[0] * m.M[1][0] + homo_p[1] * m.M[1][1] + homo_p[2] * m.M[1][2],
107 homo_p[0] * m.M[2][0] + homo_p[1] * m.M[2][1] + homo_p[2] * m.M[2][2]
110 /* Convert p back to Cartesian coordinates */
111 const Point result_p = {
112 .x = trans_p[0] / trans_p[2],
113 .y = trans_p[1] / trans_p[2]
120 Triangle triangle_mat3x3_product(Triangle t, mat3x3 m)
123 .p1 = point_mat3x3_product(t.p1, m),
124 .p2 = point_mat3x3_product(t.p2, m),
125 .p3 = point_mat3x3_product(t.p3, m)