Changeset 6617 in orxonox.OLD for trunk/src/lib/math/rotation_OBSOLETE.cc
- Timestamp:
- Jan 19, 2006, 12:45:55 PM (18 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/math/rotation_OBSOLETE.cc
r6616 r6617 11 11 ### File Specific: 12 12 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: ... 19 14 */ 20 15 21 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH 22 17 23 #include " vector.h"18 #include "rotation_OBSOLETE.h" 24 19 #ifdef DEBUG 25 20 #include "debug.h" … … 30 25 31 26 using namespace std; 32 33 /////////////34 /* VECTORS */35 /////////////36 /**37 * returns the this-vector normalized to length 1.038 * @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() const41 {42 float l = this->len();43 if(unlikely(l == 1.0 || l == 0.0))44 return *this;45 else46 return (*this / l);47 }48 49 /**50 * Vector is looking in the positive direction on all axes after this51 */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 Vector62 */63 void Vector::debug() const64 {65 PRINT(0)("x: %f; y: %f; z: %f", x, y, z);66 PRINT(0)(" lenght: %f", len());67 PRINT(0)("\n");68 }69 27 70 28 /** … … 223 181 return t; 224 182 } 225 226 /**227 * calculate the distance between two lines228 * @param l: the other line229 * @return the distance between the lines230 */231 float Line::distance (const Line& l) const232 {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 point243 * @param v: the point244 * @return the distance between the Line and the point245 */246 float Line::distancePoint (const Vector& v) const247 {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 point255 * @param v: the point256 * @return the distance between the Line and the point257 */258 float Line::distancePoint (const sVec3D& v) const259 {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 lines268 * @param l: the other line269 * @return a Vector[2] (!has to be deleted after use!) containing the two points of minimal distance270 */271 Vector* Line::footpoints (const Line& l) const272 {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 line283 \return the lenght of the line284 */285 float Line::len() const286 {287 return a.len();288 }289 290 /**291 * rotate the line by given rotation292 * @param rot: a rotation293 */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 points304 * @param a: first point305 * @param b: second point306 * @param c: third point307 */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 normal316 * @param norm: normal vector317 * @param p: anchor point318 */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 normal328 * @param norm: normal vector329 * @param p: anchor point330 */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 line341 * @param l: a line342 */343 Vector Plane::intersectLine (const Line& l) const344 {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 point352 * @param p: a Point353 * @return the distance between the plane and the point (can be negative)354 */355 float Plane::distancePoint (const Vector& p) const356 {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 point365 * @param p: a Point366 * @return the distance between the plane and the point (can be negative)367 */368 float Plane::distancePoint (const sVec3D& p) const369 {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 Plane379 * @param p: a Point380 * @return 0 if the point is contained within the Plane, positive(negative) if the point is in the positive(negative) semi-space of the Plane381 */382 float Plane::locatePoint (const Vector& p) const383 {384 return (n.dot(p) + k);385 }386
Note: See TracChangeset
for help on using the changeset viewer.