1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2025-04-21 12:27:27 +03:00

Initial commit. For older history, see project ben-scans.

http://projects.qi-hardware.com/index.php/p/ben-scans/
This commit is contained in:
Werner Almesberger
2010-09-25 04:46:16 -03:00
commit e8d6837065
23 changed files with 2139 additions and 0 deletions

66
solidify/matrix.c Normal file
View File

@@ -0,0 +1,66 @@
/*
* matrix.c - 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.
*/
#include <assert.h>
#include "matrix.h"
void matrix_identity(struct matrix *m)
{
m->a[0][0] = m->a[1][1] = 1;
m->a[0][1] = m->a[1][0] = 0;
m->b[0] = m->b[1] = 0;
}
void matrix_invert(const double m[2][2], double res[2][2])
{
double det = m[0][0]*m[1][1]-m[0][1]*m[1][0];
assert(res != (void *) m);
res[0][0] = m[1][1]/det;
res[0][1] = -m[0][1]/det;
res[1][0] = -m[1][0]/det;
res[1][1] = m[0][0]/det;
}
void matrix_mult(double a[2][2], double b[2][2], double res[2][2])
{
assert(res != a);
assert(res != b);
res[0][0] = a[0][0]*b[0][0]+a[0][1]*b[1][0];
res[0][1] = a[0][0]*b[0][1]+a[0][1]*b[1][1];
res[1][0] = a[1][0]*b[0][0]+a[1][1]*b[1][0];
res[1][1] = a[1][0]*b[0][1]+a[1][1]*b[1][1];
}
void matrix_multv(const double v[2], double m[2][2], double res[2])
{
double tmp;
tmp = v[0]*m[0][0]+v[1]*m[0][1];
res[1] = v[0]*m[1][0]+v[1]*m[1][1];
res[0] = tmp;
}
void matrix_copy(double from[2][2], double to[2][2])
{
to[0][0] = from[0][0];
to[0][1] = from[0][1];
to[1][0] = from[1][0];
to[1][1] = from[1][1];
}