/* Mathematiques de l'informatique graphique */ /* Transformation geometrique 3D */ /* en coordonnees homogenes */ /* */ /* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Mars 2019 */ #include #include #include #include "TG3D.h" #include "CH3D.h" /* Constructeurs */ TG3D::TG3D(void) { for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) c[i][j] = ( i == j ) ? 1.0 : 0.0; } TG3D::TG3D(TG3D *tg) { for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) c[i][j] = tg->c[i][j]; } /* Destructeur */ TG3D::~TG3D(void) { } /* Methode d'affichage texte */ void TG3D::print(void) { for ( int i = 0 ; i < 4 ; i++ ) printf("%10.4lf %10.4lf %10.4lf %10.4lf\n",c[i][0],c[i][1],c[i][2],c[i][3]); } /* Methode de transformation */ /* des coordonnees homogenes ch par this */ /* ch = this * ch */ void TG3D::transformation(CH3D *ch) { CH3D aux; for ( int i = 0 ; i < 4 ; i++ ) { aux.c[i] = 0.0; for ( int j = 0 ; j < 4 ; j++ ) aux.c[i] += c[i][j]*ch->c[j]; } for ( int i = 0 ; i < 4 ; i++ ) ch->c[i] = aux.c[i]; } /* Methode de composition */ /* de la transformation geometrique tg1 */ /* par la transformation geometrique tg2 */ /* avec stockage du resultat dans this */ /* this = tg1 * tg2 */ void TG3D::composition(TG3D *tg1,TG3D *tg2) { TG3D aux; for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) { aux.c[i][j] = 0.0; for ( int k = 0 ; k < 4 ; k++ ) aux.c[i][j] += tg1->c[i][k]*tg2->c[k][j]; } for ( int i = 0 ; i < 4 ; i++ ) for ( int j = 0 ; j < 4 ; j++ ) c[i][j] = aux.c[i][j]; }