00001 /* 00002 * lib-spamod : Visualisation des objets en discret. 00003 * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC 00004 * http://www.sic.sp2mi.univ-poitiers.fr/ 00005 * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS, 00006 * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/ 00007 * 00008 * This file is part of lib-spamod 00009 * 00010 * This program is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU Lesser General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 /****************************************************************************** 00025 * Fichier : Vector3D.h * 00026 * Auteur : DEXET Martine * 00027 *----------------------------------------------------------------------------* 00028 * Ce fichier contient la sp�cification de la classe Vector3D. Cette classe * 00029 * permet de repr�senter un vecteur � l'aide de trois nombres � virgule * 00030 * flottante correspondants aux trois composantes d'un vecteur. * 00031 * * 00032 *****************************************************************************/ 00033 00034 00035 #ifndef VECTOR3D_H 00036 #define VECTOR3D_H 00037 00038 #include "vertex.hh" 00039 00040 00041 00042 /****************************************************************************** 00043 * Classe Vector3D * 00044 *****************************************************************************/ 00045 00046 class Vector3D : public CVertex { 00047 00048 public: 00049 00050 // Constructeurs. 00051 Vector3D(); 00052 Vector3D(float vx, float vy, float vz); 00053 Vector3D(Vector3D const & v); 00054 Vector3D(CVertex const & p1, CVertex const & p2); 00055 00056 // M�thode calculant la longueur d'un vecteur. 00057 float Get_Length(); 00058 00059 // M�thode permettant la normalisation d'un vecteur. 00060 void Normalize(); 00061 00062 // M�thode calculant le produit scalaire de deux vecteurs. 00063 float Scal_Product(Vector3D const & v); 00064 00065 // M�thode calculant le produit vectoriel de deux vecteurs. 00066 Vector3D Vect_Product(Vector3D const & v); 00067 }; 00068 00069 /****************************************************************************** 00070 * Fichier : Vector3D.inl * 00071 * Auteur : DEXET Martine * 00072 *----------------------------------------------------------------------------* 00073 * Ce fichier contient l'impl�mentation des m�thodes de la classe Vector3D * 00074 * * 00075 *****************************************************************************/ 00076 00077 00078 // Constructeurs. 00079 inline 00080 Vector3D::Vector3D() 00081 : CVertex(0.0, 0.0, 0.0) 00082 { 00083 } 00084 00085 00086 inline 00087 Vector3D::Vector3D(float vx, float vy, float vz) 00088 :CVertex(vx, vy, vz) 00089 { 00090 } 00091 00092 inline 00093 Vector3D::Vector3D(Vector3D const & v) 00094 :CVertex(v) 00095 { 00096 } 00097 00098 inline 00099 Vector3D::Vector3D(CVertex const & p1, CVertex const & p2) 00100 :CVertex( p2.getX() - p1.getX(), p2.getY() - p1.getY(), p2.getZ() - p1.getZ()) 00101 { 00102 } 00103 00104 00105 // M�thode calculant la longueur d'un vecteur. 00106 inline 00107 float Vector3D::Get_Length() 00108 { 00109 return norm(); 00110 } 00111 00112 00113 // M�thode permettant la normalisation d'un vecteur. 00114 inline 00115 void Vector3D::Normalize() 00116 { 00117 float n = norm(); 00118 if (!isZero(n)) *this/n; 00119 } 00120 00121 00122 // M�thode calculant le produit scalaire de deux vecteurs. 00123 inline 00124 float Vector3D::Scal_Product(Vector3D const & v) 00125 { 00126 Vector3D v1 = *this; 00127 Vector3D v2 = v; 00128 00129 v1.Normalize(); 00130 v2.Normalize(); 00131 00132 return v1.dot(v2); 00133 } 00134 00135 00136 // M�thode calculant le produit vectoriel de deux vecteurs. 00137 inline 00138 Vector3D Vector3D::Vect_Product(Vector3D const & v) 00139 { 00140 return Vector3D(getY()*v.getZ() - v.getY()*getZ(), 00141 getZ()*v.getX() - v.getZ()*getX(), 00142 getX()*v.getY() - v.getX()*getY()); 00143 } 00144 00145 #endif