/* Mathematiques de l'Infographie */ /* Test des classes CH3D, Pos3D et Dir3D */ /* */ /* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Mars 2020 */ #include #include "Pos3D.h" #include "Dir3D.h" ////////////////////////////////////////////////// #include /* Fonction de test de la planarite */ /* d'une facette à quatre sommets */ int testPlanarite(Pos3D *p1,Pos3D *p2,Pos3D *p3,Pos3D *p4) { const float EPSILON = 0.000001F; Dir3D d12(p1,p2); Dir3D d13(p1,p3); Dir3D d14(p1,p4); d12.produitVectoriel(&d14); float ps = d13.produitScalaire(&d12); return(fabs(ps) < EPSILON); } int main(void) { { Pos3D *p0 = new Pos3D(); p0->print(); printf("\n"); delete(p0); } { Pos3D p1(2.0F,3.0F,4.0F); p1.print(); printf("\n"); } { Pos3D *p2 = new Pos3D(-1.1F,-0.2F,-2.3F); p2->print(); printf("\n"); delete(p2); } printf("\n"); { Dir3D *d0 = new Dir3D(); d0->print(); printf("\n"); delete(d0); } { Dir3D d1(1.1F,2.3F,-2.1F); d1.print(); printf("\n"); } { Pos3D p1(2.0F,3.0F,4.0F); Pos3D *p2 = new Pos3D(-1.1F,-0.2F,-2.3F); Dir3D *d2 = new Dir3D(&p1,p2); d2->print(); printf("\n"); delete(p2); delete(d2); } printf("\n"); { Dir3D d1(1.1F,2.3F,-2.1F); Pos3D p1(2.0F,3.0F,4.0F); Pos3D *p2 = new Pos3D(-1.1F,-0.2F,-2.3F); Dir3D *d2 = new Dir3D(&p1,p2); printf("%f\n",d1.norme()); printf("%f\n",d2->norme()); d1.normalisation(); d2->normalisation(); d1.print(); printf(" %25.20f\n",d1.norme()); d2->print(); printf(" %25.20f\n",d2->norme()); delete(p2); delete(d2); } printf("\n"); { Dir3D d1(1.1F,2.3F,-2.1F); Pos3D p1(2.0F,3.0F,4.0F); Pos3D *p2 = new Pos3D(-1.1F,-0.2F,-2.3F); Dir3D *d2 = new Dir3D(&p1,p2); printf("%f\n",d1.produitScalaire(d2)); printf("%f\n",d2->produitScalaire(&d1)); printf("%f\n",Dir3D::produitScalaire(&d1,d2)); delete(d2); } printf("\n"); { Dir3D *pv1 = new Dir3D(1.1F,2.3F,-2.1F); Dir3D *pv2 = new Dir3D(-1.1F,-0.2F,-2.3F); Dir3D pv3; Dir3D::produitVectoriel(pv1,pv2,&pv3); pv3.print(); printf("\n"); Dir3D::produitVectoriel(pv1,pv2,pv1); pv1->print(); printf("\n"); delete(pv1); pv1 = new Dir3D(1.1F,2.3F,-2.1F); Dir3D::produitVectoriel(pv1,pv2,pv2); pv2->print(); printf("\n"); delete(pv1); delete(pv2); } printf("\n"); { Dir3D *pv1 = new Dir3D(1.1F,2.3F,-2.1F); Dir3D *pv2 = new Dir3D(-1.1F,-0.2F,-2.3F); Dir3D pv3; pv3.produitVectoriel(pv1,pv2); pv3.print(); printf("\n"); pv1->produitVectoriel(pv1,pv2); pv1->print(); printf("\n"); delete(pv1); pv1 = new Dir3D(1.1F,2.3F,-2.1F); pv2->produitVectoriel(pv1,pv2); pv2->print(); printf("\n"); delete(pv1); delete(pv2); } printf("\n"); { Dir3D *pv1 = new Dir3D(1.1F,2.3F,-2.1F); Dir3D *pv2 = new Dir3D(-1.1F,-0.2F,-2.3F); pv1->produitVectoriel(pv2); pv1->print(); printf("\n"); delete(pv1); pv1 = new Dir3D(1.1F,2.3F,-2.1F); pv2->produitVectoriel(pv1); pv2->print(); printf("\n"); delete(pv1); delete(pv2); } printf("\n"); { Pos3D p1(2.0, 3.0, 4.0); Pos3D p2(6.0, 1.0, 1.0); Pos3D p3(3.0, 7.0, 5.0); Pos3D p4(7.0,-13.0,-5.0); Pos3D p5(7.0,-13.0,-6.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"); printf("P5 : "); p5.print(); printf("\n"); if ( testPlanarite(&p1,&p2,&p3,&p4) ) printf("Facette (P1,P2,P3,P4) planaire\n"); else printf("Facette (P1,P2,P3,P4) non planaire\n"); if ( testPlanarite(&p1,&p2,&p3,&p5) ) printf("Facette (P1,P2,P3,P5) planaire\n"); else printf("Facette (P1,P2,P3,P5) non planaire\n"); } getchar(); return(0); } //////////////////////////////////////////////////