#include "geom_tin.h" /////////////////////////////////////////////////////////////////////////////// // determinant - computes the determinant of a 2x2 matrix // long determinant(COORD a, COORD b,COORD c,COORD d){ return ((a*d) - (b*c)); } /////////////////////////////////////////////////////////////////////////////// // interpolate - given and triangle and x,y; interpolate z // long interpolate(COORD* p1, COORD* p2, COORD* p3, COORD px, COORD py) { long d1 = determinant((p2[Y]-p1[Y]), (p2[Z]-p1[Z]), (p3[Y]-p1[Y]), (p3[Z]-p1[Z])); long d2 = determinant((p2[X]-p1[X]), (p2[Z]-p1[Z]), (p3[X]-p1[X]), (p3[Z]-p1[Z])); long d3 = determinant((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 ((( ((py - p1[Y]) * d2) - ((px - p1[X]) * d1) ) / d3) + p1[Z]); } /////////////////////////////////////////////////////////////////////////////// // findError - find the error of a given point in a triangle // long findError(int row,int col, int height, TRIANGLE* t) { long err = interpolate(t->p1,t->p2,t->p3, row, col); return fabs((long)height-err); } /* /////////////////////////////////////////////////////////////////////////////// */ /* // determinant - computes the determinant of a 2x2 matrix */ /* // */ /* double determinant(COORD a, COORD b,COORD c,COORD d){ */ /* return ((a*d) - (b*c)); */ /* } */ /* /////////////////////////////////////////////////////////////////////////////// */ /* // interpolate - given and triangle and x,y; interpolate z */ /* // */ /* double interpolate(COORD* p1, COORD* p2, COORD* p3, COORD px, COORD py) { */ /* double d1 = determinant((p2[Y]-p1[Y]), (p2[Z]-p1[Z]), */ /* (p3[Y]-p1[Y]), (p3[Z]-p1[Z])); */ /* double d2 = determinant((p2[X]-p1[X]), (p2[Z]-p1[Z]), */ /* (p3[X]-p1[X]), (p3[Z]-p1[Z])); */ /* double d3 = determinant((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 ((( ((py - p1[Y]) * d2) - ((px - p1[X]) * d1) ) / d3) + p1[Z]); */ /* } */ /* /////////////////////////////////////////////////////////////////////////////// */ /* // findError - find the error of a given point in a triangle */ /* // */ /* double findError(int row,int col, int height, TRIANGLE* t) { */ /* double err = interpolate(t->p1,t->p2,t->p3, row, col); */ /* return fabs((double)height-err); */ /* } */