/* * geom_tin.h * * Author: Jon Todd * */ #ifndef __geom_tin_h #define __geom_tin_h #include #include #include #include "point.h" #include "triangle.h" #define X 0 #define Y 1 #define Z 2 /////////////////////////////////////////////////////////////////////// // Macros ///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// /* /////////////////////////////////////////////////////////////////////////////// */ /* // areaSign - computes the signed area of a triangle, positive if the */ /* // third point is off to the left of ab */ /* // */ /* #define areaSign(area,a,b,c){ \ */ /* double areaX; \ */ /* \ */ /* areaX = ((b[X]-a[X]) * (double)(c[Y] - a[Y])) - \ */ /* ((c[X]-a[X]) * (double)(b[Y] - a[Y])); \ */ /* \ */ /* if ( areaX > 0.5) area = 1; \ */ /* else if ( areaX < -0.5) area = -1; \ */ /* else area = 0; \ */ /* } */ /////////////////////////////////////////////////////////////////////////////// // determinant - computes the determinant of a 2x2 matrix // long determinant(COORD a, COORD b,COORD c,COORD d); /////////////////////////////////////////////////////////////////////////////// // interpolate - given and triangle and x,y; interpolate z // long interpolate(COORD* p1, COORD* p2, COORD* p3, COORD px, COORD py); /////////////////////////////////////////////////////////////////////////////// // findError - find the error of a given point in a triangle // long findError(int row,int col, int height, TRIANGLE* t); /* /////////////////////////////////////////////////////////////////////////////// */ /* // determinant - computes the determinant of a 2x2 matrix */ /* // */ /* #define determinant(det, a, b, c, d){ \ */ /* det = ((a*d) - (b*c)); \ */ /* } */ /* /////////////////////////////////////////////////////////////////////////////// */ /* // determinant3x3 - computes the determinant of a 3x3 matrix as 3 2x2 matricies */ /* // */ /* #define determinant3x3(det, a,b,c,d,e,f,g,h,i){ \ */ /* double d1,d2,d3; \ */ /* determinant(d1,e,f,h,i); \ */ /* determinant(d2,d,f,g,i); \ */ /* determinant(d3,d,e,g,h); \ */ /* \ */ /* det = (a * d1) - (b * d2) + (c * d3); \ */ /* } */ /* /////////////////////////////////////////////////////////////////////////////// */ /* // determinant4x4 - computes the determinant of a 4x4 as 4 3x3 determinants */ /* // */ /* #define determinant4x4(det, a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ \ */ /* double det1,det2,det3,det4; \ */ /* determinant3x3(det1,f,g,h,j,k,l,n,o,p);\ */ /* determinant3x3(det2,e,g,h,i,k,l,m,o,p);\ */ /* determinant3x3(det3,e,f,h,i,j,l,m,n,p);\ */ /* determinant3x3(det4,e,f,g,i,j,k,m,n,o);\ */ /* det = (a * det1) - (b * det2) + (c * det3) - (d * det4);\ */ /* } */ /* /////////////////////////////////////////////////////////////////////////////// */ /* // interpolate - given and triangle and x,y; interpolate z */ /* // */ /* #define interpolate(z,p1,p2,p3,px,py){ \ */ /* double d1,d2,d3; \ */ /* determinant(d1, (p2[Y]-p1[Y]), (p2[Z]-p1[Z]), (p3[Y]-p1[Y]), (p3[Z]-p1[Z])); \ */ /* determinant(d2, (p2[X]-p1[X]), (p2[Z]-p1[Z]), (p3[X]-p1[X]), (p3[Z]-p1[Z])); \ */ /* determinant(d3, (p2[X]-p1[X]), (p2[Y]-p1[Y]), (p3[X]-p1[X]), (p3[Y]-p1[Y])); \ */ /* \ */ /* /\* d3 should never be 0 *\/ \ */ /* if (d3 == 0){ \ */ /* printf("determinant should never be 0\n"); \ */ /* exit(1); \ */ /* } \ */ /* \ */ /* /\* return the z *\/ \ */ /* z = ((( ((py - p1[Y]) * d2) - ((px - p1[X]) * d1) ) / d3) + p1[Z]); \ */ /* \ */ /* } */ /* /////////////////////////////////////////////////////////////////////////////// */ /* // findError - find the error of a given point in a triangle */ /* // */ /* #define findError(error,row,col,height,t2) { \ */ /* double err; \ */ /* interpolate(err,t2->p1,t2->p2,t2->p3, row, col); \ */ /* error = fabs((double)height-err); \ */ /* } */ /////////////////////////////////////////////////////////////////////// // Functions ////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// #endif