Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/math/line.cc @ 10510

Last change on this file since 10510 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 2.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Christian Meyer
13   co-programmer: Patrick Boenzli : Vector::scale()
14                                    Vector::abs()
15*/
16
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH
18
19#include "line.h"
20#include "plane.h"
21#ifdef DEBUG
22  #include "debug.h"
23#else
24  #include <stdio.h>
25  #define PRINT(x) printf
26#endif
27
28
29
30/**
31 *  calculate the distance between two lines
32 * @param l: the other line
33 * @return the distance between the lines
34*/
35float Line::distance (const Line& l) const
36{
37  float q, d;
38  Vector n = a.cross(l.a);
39  q = n.dot(r-l.r);
40  d = n.len();
41  if( d == 0.0) return 0.0;
42  return q/d;
43}
44
45/**
46 *  calculate the distance between a line and a point
47 * @param v: the point
48 * @return the distance between the Line and the point
49*/
50float Line::distancePoint (const Vector& v) const
51{
52  Vector d = v-r;
53  Vector u = a * d.dot( a);
54  return (d - u).len();
55}
56
57/**
58 *  calculate the distance between a line and a point
59 * @param v: the point
60 * @return the distance between the Line and the point
61 */
62float Line::distancePoint (const sVec3D& v) const
63{
64  Vector s(v[0], v[1], v[2]);
65  Vector d = s - r;
66  Vector u = a * d.dot( a);
67  return (d - u).len();
68}
69
70/**
71 *  calculate the two points of minimal distance of two lines
72 * @param l: the other line
73 * @return a Vector[2] (!has to be deleted after use!) containing the two points of minimal distance
74*/
75Vector* Line::footpoints (const Line& l) const
76{
77  Vector* fp = new Vector[2];
78  Plane p = Plane (r + a.cross(l.a), r, r + a);
79  fp[1] = p.intersectLine (l);
80  p = Plane (fp[1], l.a);
81  fp[0] = p.intersectLine (*this);
82  return fp;
83}
84
85/**
86  \brief calculate the length of a line
87  \return the lenght of the line
88*/
89float Line::len() const
90{
91  return a.len();
92}
93
94/**
95 *  rotate the line by given rotation
96 * @param rot: a rotation
97*/
98void Line::rotate (const Rotation& rot)
99{
100  Vector t = a + r;
101  t = rotateVector( t, rot);
102  r = rotateVector( r, rot),
103  a = t - r;
104}
Note: See TracBrowser for help on using the repository browser.