mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 20:08:38 +02:00
46 lines
1.1 KiB
C
46 lines
1.1 KiB
C
/*
|
|
* matrix.h - 2D matrix operations
|
|
*
|
|
* Written 2010 by Werner Almesberger
|
|
* Copyright 2010 by Werner Almesberger
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
#ifndef MATRIX_H
|
|
#define MATRIX_H
|
|
|
|
/*
|
|
* 2D transformation:
|
|
*
|
|
* x' = x*a[0][0]+y*a[0][1]+b[0]
|
|
* y' = x*a[1][0]+y*a[1][1]+b[1]
|
|
*/
|
|
|
|
|
|
struct matrix {
|
|
double a[2][2];
|
|
double b[2];
|
|
};
|
|
|
|
|
|
void matrix_identity(struct matrix *m);
|
|
void matrix_invert(const double m[2][2], double res[2][2]);
|
|
void matrix_mult(double a[2][2], double b[2][2], double res[2][2]);
|
|
void matrix_multv(const double v[2], double m[2][2], double res[2]);
|
|
void matrix_copy(double from[2][2], double to[2][2]);
|
|
|
|
|
|
static inline void matrix_map(int x, int y, const struct matrix *m,
|
|
double *res_x, double *res_y)
|
|
{
|
|
*res_x = x*m->a[0][0]+y*m->a[0][1]+m->b[0];
|
|
*res_y = x*m->a[1][0]+y*m->a[1][1]+m->b[1];
|
|
|
|
}
|
|
|
|
#endif /* !MATRIX_H */
|