Biomechanical Joint Model
 Author: Anderson Maciel

bunny/vector.H

Go to the documentation of this file.
00001 /************************************************************************\
00002 
00003   Copyright 1997 The University of North Carolina at Chapel Hill.
00004   All Rights Reserved.
00005 
00006   Permission to use, copy, modify and distribute this software
00007   and its documentation for educational, research and non-profit
00008   purposes, without fee, and without a written agreement is
00009   hereby granted, provided that the above copyright notice and
00010   the following three paragraphs appear in all copies.
00011 
00012   IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL
00013   HILL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
00014   INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
00015   ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
00016   EVEN IF THE UNIVERSITY OF NORTH CAROLINA HAVE BEEN ADVISED OF
00017   THE POSSIBILITY OF SUCH DAMAGES.
00018 
00019 
00020   Permission to use, copy, modify and distribute this software
00021   and its documentation for educational, research and non-profit
00022   purposes, without fee, and without a written agreement is
00023   hereby granted, provided that the above copyright notice and
00024   the following three paragraphs appear in all copies.
00025 
00026   THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY
00027   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00028   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029   PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
00030   BASIS, AND THE UNIVERSITY OF NORTH CAROLINA HAS NO OBLIGATION
00031   TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
00032   MODIFICATIONS.
00033 
00034 
00035    --------------------------------- 
00036   |Please send all BUG REPORTS to:  |
00037   |                                 |
00038   |   geom@cs.unc.edu               |
00039   |                                 |
00040    ---------------------------------
00041   
00042      
00043   The authors may be contacted via:
00044 
00045   US Mail:  A. Pattekar/J. Cohen/T. Hudson/S. Gottschalk/M. Lin/D. Manocha
00046             Department of Computer Science
00047             Sitterson Hall, CB #3175
00048             University of N. Carolina
00049             Chapel Hill, NC 27599-3175
00050             
00051   Phone:    (919)962-1749
00052             
00053   EMail:    geom@cs.unc.edu
00054 
00055 \************************************************************************/
00056 #ifndef VECTOR_H
00057 #define VECTOR_H
00058 
00059 #include <math.h>
00060 
00061 #define EPS 0.0001
00062 
00063 class Vector{
00064 public:
00065   double v[3];
00066 
00067   Vector()
00068     {
00069     }
00070   
00071   
00072   Vector(double v0, double v1, double v2)
00073     {
00074       v[0] = v0;
00075       v[1] = v1;
00076       v[2] = v2;
00077     }
00078   
00079   
00080   Vector(const Vector& p)
00081     {
00082       v[0] = p.v[0];
00083       v[1] = p.v[1];
00084       v[2] = p.v[2];
00085     }
00086 
00087   Vector& operator=(const Vector& rhs)
00088     {
00089       v[0] = rhs.v[0];
00090       v[1] = rhs.v[1];
00091       v[2] = rhs.v[2];
00092       
00093       return *this;
00094     }
00095 
00096   double& operator[](int i)
00097     {
00098       return v[i];
00099     }
00100 
00101   Vector operator+(const Vector& b)
00102     {
00103       Vector sum;
00104 
00105       sum[0] = v[0]+b.v[0];
00106       sum[1] = v[1]+b.v[1];
00107       sum[2] = v[2]+b.v[2];
00108 
00109       return sum;
00110     }
00111 
00112   Vector operator-(const Vector& b)
00113     {
00114       Vector diff;
00115 
00116       diff[0] = v[0]-b.v[0];
00117       diff[1] = v[1]-b.v[1];
00118       diff[2] = v[2]-b.v[2];
00119 
00120       return diff;
00121 
00122     }
00123   
00124 
00125   Vector operator*(double term)
00126   {
00127     Vector result;
00128     
00129     result[0] = v[0] * term;
00130     result[1] = v[1] * term;
00131     result[2] = v[2] * term;
00132     
00133     return result;
00134     
00135   }
00136   
00137 
00138   Vector operator/(double denom)
00139     {
00140       Vector result;
00141 
00142       result[0] = v[0] / denom;
00143       result[1] = v[1] / denom;
00144       result[2] = v[2] / denom;
00145 
00146       return result;
00147 
00148     }
00149 
00150   
00151   Vector operator*(const Vector& b) /* cross product */
00152     {
00153       Vector result;
00154     
00155       result[0] = v[1]*b.v[2] - b.v[1]*v[2];
00156       result[1] = b.v[0]*v[2] - v[0]*b.v[2];
00157       result[2] = v[0]*b.v[1] - b.v[0]*v[1];
00158     
00159       return result;
00160 
00161     }
00162 
00163   double operator/(const Vector& b) /* dot product */
00164     {
00165       double result;
00166 
00167       result = v[0]*b.v[0] + v[1]*b.v[1] + v[2]*b.v[2];
00168       return result;
00169     }
00170 
00171   void normalize(void)
00172     {
00173       
00174       double length = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00175       
00176       if (length > EPS)
00177         {
00178           v[0] /= length;
00179           v[1] /= length;
00180           v[2] /= length;
00181         }
00182       
00183     }
00184 
00185   double length()
00186     {
00187       return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00188     }
00189   
00190 };
00191 
00192 #endif

Generated on Thu Dec 1 10:13:40 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5