Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4476 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Jun 2, 2005, 4:03:50 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk :documented the vector class

Location:
orxonox/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.in

    r4457 r4476  
    420420          esac; \
    421421        done; \
    422         echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  src/Makefile'; \
     422        echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/Makefile'; \
    423423        cd $(top_srcdir) && \
    424           $(AUTOMAKE) --foreign  src/Makefile
     424          $(AUTOMAKE) --gnu  src/Makefile
    425425.PRECIOUS: Makefile
    426426Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
  • orxonox/trunk/src/lib/math/vector.cc

    r4372 r4476  
    2525
    2626/**
    27    \brief add two vectors
    28    \param v: the other vector
    29    \return the sum of both vectors
    30 */
    31 
    32 //Vector Vector::operator+ (const Vector& v) const
    33 
    34 
    35 /**
    36    \brief subtract a vector from another
    37    \param v: the other vector
    38    \return the difference between the vectors
    39 */
    40 //Vector Vector::operator- (const Vector& v) const
    41 
    42 
    43 /**
    44    \brief calculate the dot product of two vectors
    45    \param v: the other vector
    46    \return the dot product of the vectors
    47 */
    48 //float Vector::operator* (const Vector& v) const
    49 
    50 
    51 /**
    52    \brief multiply a vector with a float
    53    \param f: the factor
    54    \return the vector multipied by f
    55 */
    56 //Vector Vector::operator* (float f) const
    57 
    58 
    59 /**
    60    \brief divide a vector with a float
    61    \param f: the divisor
    62    \return the vector divided by f   
    63 */
    64 Vector Vector::operator/ (float f) const
    65 {
    66   if( unlikely(f == 0.0))
    67   {
    68     // Prevent divide by zero
    69     return Vector (0,0,0);
    70   }
    71   return Vector(x / f, y / f, z / f);
    72 }
    73 
    74 /**
    75    \brief calculate the dot product of two vectors
    76    \param v: the other vector
    77    \return the dot product of the vectors
    78 */
    79 float Vector::dot (const Vector& v) const
    80 {
    81   return x*v.x+y*v.y+z*v.z;
    82 }
    83 
    84 /**
    85   \brief calculate the cross product of two vectors
    86   \param v: the other vector
    87         \return the cross product of the vectors
    88 */
    89 //Vector Vector::cross (const Vector& v) const
    90 
    91  
    92 /**
    93    \brief normalizes the vector to lenght 1.0
    94 */
    95 //void Vector::normalize ()
    96 
    97 
    98 /**
    99    \brief returns the voctor normalized to length 1.0
    100 */
    101 
     27   \brief returns the this-vector normalized to length 1.0
     28*/
    10229Vector Vector::getNormalized() const
    10330{
     
    11441  return *this / l;
    11542}
    116 
    117 /**
    118    \brief scales this Vector with Vector v.
    119    \param v the vector to scale this vector with
    120 */
    121 void Vector::scale(const Vector& v)
    122 {
    123   x *= v.x;
    124   y *= v.y;
    125   z *= v.z;
    126 }
    127 
    128  
    129 /**
    130    \brief calculates the lenght of the vector
    131    \return the lenght of the vector
    132 */
    133 //float Vector::len () const
    134 
    135 
    136 /**
    137    \brief Vector is looking in the positive direction on all axes after this
    138 */
    139 Vector Vector::abs()
    140 {
    141   Vector v(fabs(x), fabs(y), fabs(z));
    142   return v;
    143 }
    144 
    145 /**
    146    \brief calculate the angle between two vectors in radiances
    147    \param v1: a vector
    148    \param v2: another vector
    149    \return the angle between the vectors in radians
    150 */
    151 float angleRad (const Vector& v1, const Vector& v2)
    152 {
    153   return acos( v1 * v2 / (v1.len() * v2.len()));
    154 }
    155 
    156 
    157 /**
    158    \brief calculate the angle between two vectors in degrees
    159    \param v1: a vector
    160    \param v2: another vector
    161    \return the angle between the vectors in degrees
    162 */
    163 float angleDeg (const Vector& v1, const Vector& v2)
    164 {
    165   float f;
    166   f = acos( v1 * v2 / (v1.len() * v2.len()));
    167   return f * 180 / PI;
    168 }
    169 
    17043
    17144/**
  • orxonox/trunk/src/lib/math/vector.h

    r4372 r4476  
    2020class Vector {
    2121
    22   public:
    23  
    24   float x; //!< The x Coordinate of the Vector.
    25   float y; //!< The y Coordinate of the Vector.
    26   float z; //!< The z Coordinate of the Vector.
    27 
     22
     23 public:
    2824  Vector (float x, float y, float z) : x(x), y(y), z(z) {}  //!< assignment constructor
    2925  Vector () : x(0), y(0), z(0) {}
    3026  ~Vector () {}
    3127
    32   inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); }
    33   inline const Vector& operator+= (const Vector& v) {this->x += v.x; this->y += v.y; this->z += v.z; return *this;}
     28  /**  \param v The vector to add \returns the addition between two vectors (this + v) */
     29  inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); };
     30  /** \param v The vector to add  \returns the addition between two vectors (this += v) */
     31  inline const Vector& operator+= (const Vector& v) { this->x += v.x; this->y += v.y; this->z += v.z; return *this; };
     32  /** \param v The vector to substract  \returns the substraction between two vectors (this - v) */
    3433  inline Vector operator- (const Vector& v) const { return Vector(x - v.x, y - v.y, z - v.z); }
    35   inline const Vector& operator-= (const Vector& v) {this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this;}
    36   inline float operator* (const Vector& v) const { return x * v.x + y * v.y + z * v.z; }
    37   inline const Vector& operator*= (const Vector& v) {this->x *= v.x; this->y *= v.y; this->z *= v.z; return *this;}
    38   inline Vector operator* (float f) const { return Vector(x * f, y * f, z * f); }
    39   inline const Vector& operator*= (float f) {this->x *= f; this->y *= f; this->z *= f; return *this;}
    40   Vector operator/ (float f) const;
    41   inline const Vector& operator/= (float f) {this->x /= f; this->y /= f; this->z /= f; return *this;}
    42   inline const Vector& operator= (const Vector& v) {this->x = v.x; this->y = v.y; this->z = v.z; return *this;}
    43   float dot (const Vector& v) const;
     34  /** \param v The vector to substract  \returns the substraction between two vectors (this -= v) */
     35  inline const Vector& operator-= (const Vector& v) { this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this; };
     36  /** \param v the second vector  \returns The dotProduct between two vector (this (dot) v) */
     37  inline float operator* (const Vector& v) const { return x * v.x + y * v.y + z * v.z; };
     38  /** \todo strange */
     39  inline const Vector& operator*= (const Vector& v) { this->x *= v.x; this->y *= v.y; this->z *= v.z; return *this; };
     40  /** \param f a factor to multiply the vector with \returns the vector multiplied by f (this * f) */
     41  inline Vector operator* (float f) const { return Vector(x * f, y * f, z * f); };
     42  /** \param f a factor to multiply the vector with \returns the vector multiplied by f (this *= f) */
     43  inline const Vector& operator*= (float f) { this->x *= f; this->y *= f; this->z *= f; return *this; };
     44  /** \param f a factor to divide the vector with \returns the vector divided by f (this / f) */
     45  inline Vector operator/ (float f) const {if (unlikely(f == 0.0)) return Vector(0,0,0); else return Vector(this->x / f, this->y / f, this->z / f); };
     46  /** \param f a factor to divide the vector with \returns the vector divided by f (this /= f) */
     47  inline const Vector& operator/= (float f) {if (unlikely(f == 0.0)) {this->x=0;this->y=0;this->z=0;} else {this->x /= f; this->y /= f; this->z /= f;} return *this; };
     48  /** \brief copy constructor \todo (i do not know it this is faster) \param v the vector to assign to this vector. \returns the vector v */
     49  inline const Vector& operator= (const Vector& v) { this->x = v.x; this->y = v.y; this->z = v.z; return *this; };
     50  /** \param v: the other vector \return the dot product of the vectors */
     51  float dot (const Vector& v) const { return x*v.x+y*v.y+z*v.z; };
     52  /** \param v: the corss-product partner \returns the cross-product between this and v (this (x) v) */
    4453  inline Vector cross (const Vector& v) const { return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
    45   void scale(const Vector& v);
     54  /** \param scales the this vector with v */
     55  void scale(const Vector& v) {   x *= v.x;  y *= v.y; z *= v.z; };
     56  /** \returns the length of the vector */
    4657  inline float len() const { return sqrt (x*x+y*y+z*z); }
    47   inline void normalize() {
     58  /** \brief normalizes the vector */
     59  inline void normalize() {
    4860                      float l = len();
    4961                      if( unlikely(l == 0.0))
     
    6072
    6173  void debug() const;
    62 };
    63 
    64 float angleDeg (const Vector& v1, const Vector& v2);
    65 float angleRad (const Vector& v1, const Vector& v2);
     74
     75 public:
     76  float    x;     //!< The x Coordinate of the Vector.
     77  float    y;     //!< The y Coordinate of the Vector.
     78  float    z;     //!< The z Coordinate of the Vector.
     79};
     80
     81/**
     82   \brief calculate the angle between two vectors in radiances
     83   \param v1: a vector
     84   \param v2: another vector
     85   \return the angle between the vectors in radians
     86*/
     87inline float angleDeg (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())); };
     88/**
     89   \brief calculate the angle between two vectors in degrees
     90   \param v1: a vector
     91   \param v2: another vector
     92   \return the angle between the vectors in degrees
     93*/
     94inline float angleRad (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())) * 180/M_PI; };
     95
    6696
    6797//! Quaternion
    6898/**
    69         Class to handle 3-dimensional rotation efficiently
     99   Class to handle 3-dimensional rotation efficiently
    70100*/
    71101class Quaternion
    72102{
    73103 public:
    74   Vector v;     //!< Imaginary Vector
    75   float w;        //!< Real part of the number
     104  Vector    v;        //!< Imaginary Vector
     105  float     w;        //!< Real part of the number
    76106 
    77107  inline Quaternion () { w = 1; v = Vector(0,0,0); }
Note: See TracChangeset for help on using the changeset viewer.