Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6617 in orxonox.OLD for trunk/src/lib/math/rotation_OBSOLETE.cc


Ignore:
Timestamp:
Jan 19, 2006, 12:45:55 PM (18 years ago)
Author:
bensch
Message:

trunk: split Rotation/Line/Quaternion/Plane(Rectangle) into seperate files

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/math/rotation_OBSOLETE.cc

    r6616 r6617  
    1111   ### File Specific:
    1212   main-programmer: Christian Meyer
    13    co-programmer: Patrick Boenzli : Vector::scale()
    14                                     Vector::abs()
    15 
    16    Quaternion code borrowed from an Gamasutra article by Nick Bobick and Ken Shoemake
    17 
    18    2005-06-02: Benjamin Grauer: speed up, and new Functionality to Vector (mostly inline now)
     13   co-programmer: ...
    1914*/
    2015
    2116#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH
    2217
    23 #include "vector.h"
     18#include "rotation_OBSOLETE.h"
    2419#ifdef DEBUG
    2520  #include "debug.h"
     
    3025
    3126using namespace std;
    32 
    33 /////////////
    34 /* VECTORS */
    35 /////////////
    36 /**
    37  *  returns the this-vector normalized to length 1.0
    38  * @todo there is some error in this function, that i could not resolve. it just does not, what it is supposed to do.
    39  */
    40 Vector Vector::getNormalized() const
    41 {
    42   float l = this->len();
    43   if(unlikely(l == 1.0 || l == 0.0))
    44     return *this;
    45   else
    46     return (*this / l);
    47 }
    48 
    49 /**
    50  *  Vector is looking in the positive direction on all axes after this
    51 */
    52 Vector Vector::abs()
    53 {
    54   Vector v(fabs(x), fabs(y), fabs(z));
    55   return v;
    56 }
    57 
    58 
    59 
    60 /**
    61  *  Outputs the values of the Vector
    62  */
    63 void Vector::debug() const
    64 {
    65   PRINT(0)("x: %f; y: %f; z: %f", x, y, z);
    66   PRINT(0)(" lenght: %f", len());
    67   PRINT(0)("\n");
    68 }
    6927
    7028/**
     
    223181  return t;
    224182}
    225 
    226 /**
    227  *  calculate the distance between two lines
    228  * @param l: the other line
    229  * @return the distance between the lines
    230 */
    231 float Line::distance (const Line& l) const
    232 {
    233   float q, d;
    234   Vector n = a.cross(l.a);
    235   q = n.dot(r-l.r);
    236   d = n.len();
    237   if( d == 0.0) return 0.0;
    238   return q/d;
    239 }
    240 
    241 /**
    242  *  calculate the distance between a line and a point
    243  * @param v: the point
    244  * @return the distance between the Line and the point
    245 */
    246 float Line::distancePoint (const Vector& v) const
    247 {
    248   Vector d = v-r;
    249   Vector u = a * d.dot( a);
    250   return (d - u).len();
    251 }
    252 
    253 /**
    254  *  calculate the distance between a line and a point
    255  * @param v: the point
    256  * @return the distance between the Line and the point
    257  */
    258 float Line::distancePoint (const sVec3D& v) const
    259 {
    260   Vector s(v[0], v[1], v[2]);
    261   Vector d = s - r;
    262   Vector u = a * d.dot( a);
    263   return (d - u).len();
    264 }
    265 
    266 /**
    267  *  calculate the two points of minimal distance of two lines
    268  * @param l: the other line
    269  * @return a Vector[2] (!has to be deleted after use!) containing the two points of minimal distance
    270 */
    271 Vector* Line::footpoints (const Line& l) const
    272 {
    273   Vector* fp = new Vector[2];
    274   Plane p = Plane (r + a.cross(l.a), r, r + a);
    275   fp[1] = p.intersectLine (l);
    276   p = Plane (fp[1], l.a);
    277   fp[0] = p.intersectLine (*this);
    278   return fp;
    279 }
    280 
    281 /**
    282   \brief calculate the length of a line
    283   \return the lenght of the line
    284 */
    285 float Line::len() const
    286 {
    287   return a.len();
    288 }
    289 
    290 /**
    291  *  rotate the line by given rotation
    292  * @param rot: a rotation
    293 */
    294 void Line::rotate (const Rotation& rot)
    295 {
    296   Vector t = a + r;
    297   t = rotateVector( t, rot);
    298   r = rotateVector( r, rot),
    299   a = t - r;
    300 }
    301 
    302 /**
    303  *  create a plane from three points
    304  * @param a: first point
    305  * @param b: second point
    306  * @param c: third point
    307 */
    308 Plane::Plane (const Vector& a, const Vector& b, const Vector& c)
    309 {
    310   n = (a-b).cross(c-b);
    311   k = -(n.x*b.x+n.y*b.y+n.z*b.z);
    312 }
    313 
    314 /**
    315  *  create a plane from anchor point and normal
    316  * @param norm: normal vector
    317  * @param p: anchor point
    318 */
    319 Plane::Plane (const Vector& norm, const Vector& p)
    320 {
    321   n = norm;
    322   k = -(n.x*p.x+n.y*p.y+n.z*p.z);
    323 }
    324 
    325 
    326 /**
    327   *  create a plane from anchor point and normal
    328   * @param norm: normal vector
    329   * @param p: anchor point
    330 */
    331 Plane::Plane (const Vector& norm, const sVec3D& g)
    332 {
    333   Vector p(g[0], g[1], g[2]);
    334   n = norm;
    335   k = -(n.x*p.x+n.y*p.y+n.z*p.z);
    336 }
    337 
    338 
    339 /**
    340  *  returns the intersection point between the plane and a line
    341  * @param l: a line
    342 */
    343 Vector Plane::intersectLine (const Line& l) const
    344 {
    345   if (n.x*l.a.x+n.y*l.a.y+n.z*l.a.z == 0.0) return Vector(0,0,0);
    346   float t = (n.x*l.r.x+n.y*l.r.y+n.z*l.r.z+k) / (n.x*l.a.x+n.y*l.a.y+n.z*l.a.z);
    347   return l.r + (l.a * t);
    348 }
    349 
    350 /**
    351  *  returns the distance between the plane and a point
    352  * @param p: a Point
    353  * @return the distance between the plane and the point (can be negative)
    354 */
    355 float Plane::distancePoint (const Vector& p) const
    356 {
    357   float l = n.len();
    358   if( l == 0.0) return 0.0;
    359   return (n.dot(p) + k) / n.len();
    360 }
    361 
    362 
    363 /**
    364  *  returns the distance between the plane and a point
    365  * @param p: a Point
    366  * @return the distance between the plane and the point (can be negative)
    367  */
    368 float Plane::distancePoint (const sVec3D& p) const
    369 {
    370   Vector s(p[0], p[1], p[2]);
    371   float l = n.len();
    372   if( l == 0.0) return 0.0;
    373   return (n.dot(s) + k) / n.len();
    374 }
    375 
    376 
    377 /**
    378  *  returns the side a point is located relative to a Plane
    379  * @param p: a Point
    380  * @return 0 if the point is contained within the Plane, positive(negative) if the point is in the positive(negative) semi-space of the Plane
    381 */
    382 float Plane::locatePoint (const Vector& p) const
    383 {
    384   return (n.dot(p) + k);
    385 }
    386 
Note: See TracChangeset for help on using the changeset viewer.