#include "point3D.h" #include /**********************************************************************/ /**********************************************************************/ /* */ /* methodes de la classe point3D */ /* */ /**********************************************************************/ /**********************************************************************/ point3D::point3D(){ x = 0.0; y = 0.0; z = 0.0; } point3D::point3D(const double X,const double Y,const double Z){ x=X; y=Y; z=Z; } bool point3D::operator==(const point3D &op) const { return( x == op.x && y == op.y && z == op.z); } point3D& point3D::operator=(const point3D &op) { x = op.x; y = op.y; z = op.z; return *this; } point3D point3D::operator+(const point3D &op) const { return( point3D( x + op.x, y + op.y, z + op.z) ); } point3D point3D::operator-(const point3D &op) const { return( point3D( x - op.x, y - op.y, z - op.z) ); } point3D& point3D::operator*=(const double op) { x *= op; y *= op; z *= op; return *this; } point3D point3D::operator*(const double op) const { return ( point3D( x * op, y * op, z * op) ); } point3D& point3D::operator/=(const double op) { x /= op; y /= op; z /= op; return *this; } point3D point3D::operator/(const double op) const { return ( point3D( x / op, y / op, z / op) ); } ostream& operator<<(ostream& p, point3D op) { p << "(" << op.x <<", " << op.y << ", " << op.z << ")"; return(p); } istream& operator>>(istream& p, point3D &op) { cout << "Entrez x:"; p >> op.x; cout << "Entrez y:"; p >> op.y; cout << "Entrez z:"; p >> op.z; return (p); } double point3D::produit_scalaire(const point3D& _v1, const point3D& _v2){ return _v1.x * _v2.x + _v1.y * _v2.y + _v1.z * _v2.z; } point3D point3D::produit_vectoriel(const point3D& _v1 , const point3D& _v2){ //produit vectoriel point3D res; res.x = _v1.y * _v2.z - _v1.z * _v2.y; res.y = _v1.z * _v2.x - _v1.x * _v2.z; res.z = _v1.x * _v2.y - _v1.y * _v2.x; return res; } point3D point3D::PointsToVecteur(const point3D& _p1, const point3D& _p2) { point3D res; res.x = _p2.x - _p1.x; res.y = _p2.y - _p1.y; res.z = _p2.z - _p1.z; return res; } void point3D::normalize( point3D& _v) { double lenght = sqrtf(produit_scalaire(_v, _v)); _v.x /= lenght; _v.y /= lenght; _v.z /= lenght; }