1
0
mirror of git://projects.qi-hardware.com/ben-scans.git synced 2024-11-25 05:54:04 +02:00
ben-scans/solidify/matrix.c
Werner Almesberger 898970b3dd Instead of performing the tranformations stepwise for each point, pre-calculate
them once.

- solidify/matrix.h, solidify/matrix.c: 2D matrix operations
- solidify/Makefile (OBJS): added matrix.o
- solidify/face.h (struct matrix): moved to solidify/matrix.h
- solidify/overlap.c (point, merge_matrix, draw_map): precalculate a single
  vA+b transformation instead of stepwise transforming the vector inside
  the loop
- solidify/overlap.c (do_shift): now that the math is right (or at least
  better), reverse the shift
2010-09-24 16:42:36 -03:00

67 lines
1.4 KiB
C

/*
* 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];
}