Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4545 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Jun 7, 2005, 11:15:57 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: further improved the vector class, now it can be used like an array :)), finished calculation of the covariance matrix

Location:
orxonox/trunk/src/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc

    r4544 r4545  
    5757  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
    5858  float     face;                                    //!< surface area of the entire convex hull
    59   float     centroid[length];                        //!< centroid of the i'th convex hull 
     59  Vector    centroid[length];                        //!< centroid of the i'th convex hull 
     60  Vector    centre;                                  //!< the centre of the entire hull
    6061  OBB*      obb = new OBB();                         //!< the new obb to add
    6162  Vector    p, q, r;                                 //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d
    62   Vector    t1, t2;
    63 
    64   /* fist compute all the convex hull face/facelets */
    65   for(int i = 0; i < length; i+=3)
     63  Vector    t1, t2;                                  //!< temporary values
     64  float     covariance[3][3];                        //!< the covariance matrix
     65   
     66  /* fist compute all the convex hull face/facelets and centroids */
     67  for(int i = 0; i < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
    6668    {
    6769      p = *(verticesList + i);
     
    7375      /* finding the facelet surface via cross-product */
    7476      facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
    75 
    7677      /* update the entire convex hull surface */
    7778      face += facelet[i];
    78     }
    7979
    8080
     81      /* calculate the cetroid of the hull triangles */
     82      centroid[i] = (p + q + r) * 1/3;
     83      /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
     84      centre += centroid[i] * facelet[i];
     85    }
     86  /* take the average of the centroid sum */
     87  centre /= face;
     88 
     89  /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
     90  for(int j = 0; j < 3; ++j)
     91    {
     92      for(int k = 0; k < 3; ++k)
     93        {
     94          for(int i = 0; i < length; i+=3)
     95            {
     96              p = *(verticesList + i);
     97              q = *(verticesList + i + 1);
     98              r = *(verticesList + i + 2);
     99
     100              covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
     101                                                                q[j] * q[k] + r[j]*r[k]) - centre[j] * centre[k];
     102            }
     103        }
     104    }
    81105}
    82106
  • orxonox/trunk/src/lib/math/vector.h

    r4477 r4545  
    1111#include <math.h>
    1212#include "compiler.h"
     13#include "abstract_model.h"
    1314//! PI the circle-constant
    1415#define PI 3.14159265359f
     
    2627  ~Vector () {}
    2728
     29  /** \param index The index of the "array" \returns the x/y/z coordinate */
     30  inline float operator[] (float index) const {if( index == 0) return this->x; if( index == 1) return this->y; if( index == 2) return this->z;}
    2831  /**  \param v The vector to add \returns the addition between two vectors (this + v) */
    2932  inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); };
     
    4851  /** \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 */
    4952  inline const Vector& operator= (const Vector& v) { this->x = v.x; this->y = v.y; this->z = v.z; return *this; };
     53  /** \brief copy constructor  \param v the sVec3D to assign to this vector. \returns the vector v */
     54  inline const Vector& operator= (const sVec3D& v) { this->x = v[0]; this->y = v[1]; this->z = v[2]; }
    5055  /** \param v: the other vector \return the dot product of the vectors */
    5156  float dot (const Vector& v) const { return x*v.x+y*v.y+z*v.z; };
Note: See TracChangeset for help on using the changeset viewer.