/* Mathematiques de l'informatique graphique */ /* Direction en 3D */ /* */ /* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Mars 2014 */ #include #include #include #include "CoordonneesHomogenes3D.h" #include "Direction3D.h" #include "Position3D.h" Direction3D::Direction3D(void):CoordonneesHomogenes3D(0.0,0.0,0.0,0.0) { } Direction3D::Direction3D(double x,double y,double z):CoordonneesHomogenes3D(x,y,z,0.0) { } Direction3D::Direction3D(Direction3D *p):CoordonneesHomogenes3D(p) { } Direction3D::Direction3D(Position3D *p1,Position3D *p2):CoordonneesHomogenes3D() { c[0] = p2->c[0]-p1->c[0]; c[1] = p2->c[1]-p1->c[1]; c[2] = p2->c[2]-p1->c[2]; c[3] = 0.0; } Direction3D::~Direction3D(void) { } double Direction3D::normalise(void) { double d = sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2]); if ( d != 0.0 ) { c[0] /= d; c[1] /= d; c[2] /= d; } return(d); } void Direction3D::produitVectoriel(Direction3D *d1,Direction3D *d2) { double x = d1->c[1]*d2->c[2] - d1->c[2]*d2->c[1]; double y = d1->c[2]*d2->c[0] - d1->c[0]*d2->c[2]; double z = d1->c[0]*d2->c[1] - d1->c[1]*d2->c[0]; c[0] = x; c[1] = y; c[2] = z; c[3] = 0.0; } void Direction3D::produitVectoriel(Direction3D *d) { double x = c[1]*d->c[2] - c[2]*d->c[1]; double y = c[2]*d->c[0] - c[0]*d->c[2]; double z = c[0]*d->c[1] - c[1]*d->c[0]; c[0] = x; c[1] = y; c[2] = z; c[3] = 0.0; } double Direction3D::produitScalaire(Direction3D *d) { return(c[0]*d->c[0]+c[1]*d->c[1]+c[2]*d->c[2]); } /////////////////////////////////////////////////////////////////// Direction3D *Direction3D::reflexion(Direction3D *n) { double ps = produitScalaire(n); if ( ps < 0.0 ) return(NULL); Direction3D *r = new Direction3D(); r->c[0] = 2.0*ps*n->c[0]-c[0]; r->c[1] = 2.0*ps*n->c[1]-c[1]; r->c[2] = 2.0*ps*n->c[2]-c[2]; return(r); } int Direction3D::reflexion(Direction3D *i,Direction3D *n) { double ps = i->produitScalaire(n); if ( ps < 0.0 ) return(0); c[0] = 2.0*ps*n->c[0]-i->c[0]; c[1] = 2.0*ps*n->c[1]-i->c[1]; c[2] = 2.0*ps*n->c[2]-i->c[2]; c[3] = 0.0; return(1); } int Direction3D::transmission(Direction3D *i,Direction3D *n,double niSurNt) { double ps = i->produitScalaire(n); double v = 1.0-(niSurNt*niSurNt*(1.0-ps*ps)); if ( v < 0.0 ) return(0); v = niSurNt*ps-sqrt(v); c[0] = v*n->c[0] - niSurNt*i->c[0]; c[1] = v*n->c[1] - niSurNt*i->c[1]; c[2] = v*n->c[2] - niSurNt*i->c[2]; c[3] = 0.0; return(1); } ///////////////////////////////////////////////////////////////////