Root/solidify/matrix.h

1/*
2 * matrix.h - 2D matrix operations
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 by Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#ifndef MATRIX_H
14#define MATRIX_H
15
16/*
17 * 2D transformation:
18 *
19 * x' = x*a[0][0]+y*a[0][1]+b[0]
20 * y' = x*a[1][0]+y*a[1][1]+b[1]
21 */
22
23
24struct matrix {
25    double a[2][2];
26    double b[2];
27};
28
29
30void matrix_identity(struct matrix *m);
31void matrix_invert(const double m[2][2], double res[2][2]);
32void matrix_mult(double a[2][2], double b[2][2], double res[2][2]);
33void matrix_multv(const double v[2], double m[2][2], double res[2]);
34void matrix_copy(double from[2][2], double to[2][2]);
35
36
37static inline void matrix_map(int x, int y, const struct matrix *m,
38    double *res_x, double *res_y)
39{
40    *res_x = x*m->a[0][0]+y*m->a[0][1]+m->b[0];
41    *res_y = x*m->a[1][0]+y*m->a[1][1]+m->b[1];
42
43}
44
45#endif /* !MATRIX_H */
46

Archive Download this file

Branches:
master



interactive