/* Test de planarite pour une facette */ /* a quatre sommets */ /* */ /* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Octobre 2012 */ #include #include #include "Position3D.h" #include "Direction3D.h" /* Fonction de test de la planarite */ /* d'une facette à quatre sommets */ int testPlanarite(Position3D *p1,Position3D *p2,Position3D *p3,Position3D *p4) { const double EPSILON = 0.000001; Direction3D *d12 = new Direction3D(p1,p2); Direction3D *d13 = new Direction3D(p1,p3); Direction3D *d14 = new Direction3D(p1,p4); d12->produitVectoriel(d13); double ps = d14->produitScalaire(d12); delete(d12); delete(d13); delete(d14); return(fabs(ps) < EPSILON); } /* Fonction principale */ int main(int argc,char **argv) { { Position3D *p1 = new Position3D(2.0, 3.0, 4.0); Position3D *p2 = new Position3D(6.0, 1.0, 1.0); Position3D *p3 = new Position3D(3.0, 7.0, 5.0); Position3D *p4 = new Position3D(7.0,-13.0,-5.0); printf("P1 : "); p1->print(); printf("\n"); printf("P2 : "); p2->print(); printf("\n"); printf("P3 : "); p3->print(); printf("\n"); printf("P4 : "); p4->print(); printf("\n"); if ( testPlanarite(p1,p2,p3,p4) ) printf("Facette planaire\n"); else printf("Facette non planaire\n"); delete(p4); delete(p3); delete(p2); delete(p1); } printf("\n"); { Position3D *p1 = new Position3D(2.0, 3.0, 4.0); Position3D *p2 = new Position3D(6.0, 1.0, 1.0); Position3D *p3 = new Position3D(3.0, 7.0, 5.0); Position3D *p4 = new Position3D(7.0,-13.0, 0.0); printf("P1 : "); p1->print(); printf("\n"); printf("P2 : "); p2->print(); printf("\n"); printf("P3 : "); p3->print(); printf("\n"); printf("P4 : "); p4->print(); printf("\n"); if ( testPlanarite(p1,p2,p3,p4) ) printf("Facette planaire\n"); else printf("Facette non planaire\n"); delete(p4); delete(p3); delete(p2); delete(p1); } getchar(); return(0); }