diff options
author | dan miller | 2007-10-19 05:24:38 +0000 |
---|---|---|
committer | dan miller | 2007-10-19 05:24:38 +0000 |
commit | f205de7847da7ae1c10212d82e7042d0100b4ce0 (patch) | |
tree | 9acc9608a6880502aaeda43af52c33e278e95b9c /libraries/ode-0.9/OPCODE/Ice/IceSegment.cpp | |
parent | trying to fix my screwup part deux (diff) | |
download | opensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.zip opensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.gz opensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.bz2 opensim-SC-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.xz |
from the start... checking in ode-0.9
Diffstat (limited to 'libraries/ode-0.9/OPCODE/Ice/IceSegment.cpp')
-rw-r--r-- | libraries/ode-0.9/OPCODE/Ice/IceSegment.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/libraries/ode-0.9/OPCODE/Ice/IceSegment.cpp b/libraries/ode-0.9/OPCODE/Ice/IceSegment.cpp new file mode 100644 index 0000000..cd9ceb7 --- /dev/null +++ b/libraries/ode-0.9/OPCODE/Ice/IceSegment.cpp | |||
@@ -0,0 +1,57 @@ | |||
1 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
2 | /** | ||
3 | * Contains code for segments. | ||
4 | * \file IceSegment.cpp | ||
5 | * \author Pierre Terdiman | ||
6 | * \date April, 4, 2000 | ||
7 | */ | ||
8 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
9 | |||
10 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
11 | /** | ||
12 | * Segment class. | ||
13 | * A segment is defined by S(t) = mP0 * (1 - t) + mP1 * t, with 0 <= t <= 1 | ||
14 | * Alternatively, a segment is S(t) = Origin + t * Direction for 0 <= t <= 1. | ||
15 | * Direction is not necessarily unit length. The end points are Origin = mP0 and Origin + Direction = mP1. | ||
16 | * | ||
17 | * \class Segment | ||
18 | * \author Pierre Terdiman | ||
19 | * \version 1.0 | ||
20 | */ | ||
21 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
22 | |||
23 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
24 | // Precompiled Header | ||
25 | #include "Stdafx.h" | ||
26 | |||
27 | using namespace IceMaths; | ||
28 | |||
29 | float Segment::SquareDistance(const Point& point, float* t) const | ||
30 | { | ||
31 | Point Diff = point - mP0; | ||
32 | Point Dir = mP1 - mP0; | ||
33 | float fT = Diff | Dir; | ||
34 | |||
35 | if(fT<=0.0f) | ||
36 | { | ||
37 | fT = 0.0f; | ||
38 | } | ||
39 | else | ||
40 | { | ||
41 | float SqrLen= Dir.SquareMagnitude(); | ||
42 | if(fT>=SqrLen) | ||
43 | { | ||
44 | fT = 1.0f; | ||
45 | Diff -= Dir; | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | fT /= SqrLen; | ||
50 | Diff -= fT*Dir; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | if(t) *t = fT; | ||
55 | |||
56 | return Diff.SquareMagnitude(); | ||
57 | } | ||