home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / utils / graphtal.lzh / Graphtal.Amiga / Vector.h < prev    next >
C/C++ Source or Header  |  1992-11-20  |  3KB  |  98 lines

  1. /*
  2.  * Vector.h - class definitions for class Vector.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  *                     University of Berne, Switzerland
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #ifndef Vector_H
  20. # define Vector_H
  21.  
  22. #include <iostream.h>
  23. #include <math.h>
  24.  
  25. #include "mathutilities.h"
  26. #include "Error.h"
  27.  
  28. //___________________________________________________________ Vector
  29.  
  30. class Vector
  31. {
  32. public:
  33.   Vector();
  34.   Vector(const real, const real, const real); 
  35.   Vector(const Vector&);
  36.  
  37.   real& operator[](int i);
  38.   real operator[](int i) const;
  39.  
  40.   const Vector& operator=(const Vector&);
  41.   Vector& operator+=(const Vector&);
  42.   Vector& operator-=(const Vector&); 
  43.   Vector& operator*=(const Vector&); 
  44.   Vector& operator*=(const real); 
  45.   Vector& operator/=(const real); 
  46.  
  47.   int operator==(const Vector&) const;
  48.   int operator!=(const Vector&) const;
  49.  
  50.   real sqr() const;                   // squared length of vector
  51.   real length() const;                // length of vector
  52.   int  zero() const;
  53.   real distance(const Vector&) const; // distance between two points
  54.   real   normalize();                 // normalize vector
  55.   Vector normalized() const;          // generate normalized vector
  56.  
  57.   Vector operator-() const;              // negation
  58.   Vector operator+(const Vector&) const; // vector addition
  59.   Vector operator-(const Vector&) const; // vector subtraction
  60.   Vector operator*(const Vector&) const; // vector cross product
  61.   real   operator^(const Vector&) const; // vector dot product
  62.   Vector operator/(const real) const;    // scalar divison
  63.  
  64.   // scalar multiply
  65.   friend Vector operator*(real, const Vector&); 
  66.   friend Vector operator*(const Vector&, real); 
  67.  
  68.   friend ostream& operator<<(ostream&, const Vector&);
  69.  
  70.   static void swap(Vector&, Vector&);
  71.  
  72. private:
  73.   real v[3];
  74. };
  75.  
  76. inline real& Vector::operator[](int i)
  77. #ifndef __OPTIMIZE__
  78.   if (i<0 || i>2)
  79.     Error(ERR_PANIC, "Vector::operator[] index out of range");
  80. #endif
  81.  
  82.   return v[i]; 
  83. }
  84.  
  85. inline real Vector::operator[](int i) const 
  86. #ifndef __OPTIMIZE__
  87.   if (i<0 || i>2)
  88.     Error(ERR_PANIC, "Vector::operator[] index out of range");
  89. #endif
  90.  
  91.   return v[i]; 
  92. }
  93.  
  94. #endif // Vector_H
  95.  
  96.