/* 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]; } TG3D::TG3D(TG3D *tg1,TG3D *tg2) { composition(tg1,tg2); } /* Destructeur */ TG3D::~TG3D(void) { } /* Getter */ void TG3D::get(double m[4][4]) { for ( int i = 0 ; i < 4 ; i++ ) { for ( int j = 0 ; j < 4 ; j++ ) m[i][j] = c[i][j]; } } /* Setter */ bool TG3D::set(double m[4][4]) { for ( int i = 0 ; i < 4 ; i++ ) { for ( int j = 0 ; j < 4 ; j++ ) c[i][j] = m[i][j]; } return true; } /* 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) { double aux[4] = { 0.0,0.0,0.0,0.0 } ; for ( int i = 0 ; i < 4 ; i++ ) { for ( int j = 0 ; j < 4 ; j++ ) { double v; ch->get(j,&v); aux[i] += c[i][j]*v; } } for ( int i = 0 ; i < 3 ; i++ ) ch->set(aux[i],i); } /* Methode de composition */ /* de la transformation geometrique tg1 */ /* par la transformation geometrique tg2 */ /* avec stockage du resultat dans this */ /* this = tg1 * tg2 */ /* Verification de la conformite */ /* du resultat de la composition */ /* avec le type effectif de this */ bool TG3D::composition(TG3D *tg1,TG3D *tg2) { TG3D tg; tg.compositionP(tg1,tg2); double m[4][4]; tg.get(m); return set(m); } /* Methode de composition */ /* de la transformation geometrique tg1 */ /* par la transformation geometrique tg2 */ /* avec stockage du resultat dans this */ /* this = tg1 * tg2 */ void TG3D::compositionP(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]; }