 Pluecker.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
5 */
6
7 #ifndef CAFU_MATH_PLUECKER_HPP_INCLUDED
8 #define CAFU_MATH_PLUECKER_HPP_INCLUDED
9
10 #include "Vector3.hpp"
11 #include <cassert>
12
13
14 namespace cf
15 {
16  namespace math
17  {
18  /// This class represents Pluecker coordinates.
19  /// Good introductions about Pluecker coordinates are found in publications by Seth Teller
20  /// (e.g. "Visibility Computations in Densely Occluded Polyhedral Environments" (Ph.D. dissertation, Berkeley, 1992)),
21  /// at Wikipedia (http://en.wikipedia.org/wiki/Pl%C3%BCcker_co-ordinates), and many other internet sites.
22  template<class T> class PlueckerT
23  {
24  public:
25
26  /// The default constructor.
28  {
29  p=p=p=p=p=p=0;
30  }
31
32  /// Constructor for creating a Pluecker coordinate from individual components.
33  PlueckerT(const T p0, const T p1, const T p2, const T p3, const T p4, const T p5)
34  {
35  p=p0;
36  p=p1;
37  p=p2;
38  p=p3;
39  p=p4;
40  p=p5;
41  }
42
43  /// Creates a Pluecker coordinate from the line (segment) that starts at point A and ends at point B.
44  static PlueckerT CreateFromLine(const Vector3T<T>& A, const Vector3T<T>& B)
45  {
46  return PlueckerT(A.x*B.y - B.x*A.y,
47  A.x*B.z - B.x*A.z,
48  A.x - B.x,
49  A.y*B.z - B.y*A.z,
50  A.z - B.z,
51  B.y - A.y);
52  }
53
54  /// Creates a Pluecker coordinate from the ray that starts at (or "passes through") point A into direction Dir.
55  static PlueckerT CreateFromRay(const Vector3T<T>& A, const Vector3T<T>& Dir)
56  {
57  return PlueckerT(A.x*Dir.y - Dir.x*A.y,
58  A.x*Dir.z - Dir.x*A.z,
59  -Dir.x,
60  A.y*Dir.z - Dir.y*A.z,
61  -Dir.z,
62  Dir.y);
63  }
64
65
66  /// Returns the i-th component of this Pluecker coordinate.
67  T& operator [] (unsigned long i) { assert(i<6); return p[i]; }
68
69  /// Returns the i-th component of this Pluecker coordinate.
70  const T& operator [] (unsigned long i) const { assert(i<6); return p[i]; }
71
72  /// This operator computes the permuted inner product (as described in Tellers dissertation) of the two Pluecker coordinates.
73  T operator * (const PlueckerT& Other) const
74  {
75  return p*Other.p + p*Other.p + p*Other.p + p*Other.p + p*Other.p + p*Other.p;
76  }
77
78
79  // GetLine() const;
80  // GetRay() const;
81  // GetDir() const;
82
83
84  /// The six components of the Pluecker coordinate.
85  T p;
86  };
87
88
89  /// Typedef for an PlueckerT of floats.
91
92  /// Typedef for an Pluecker of doubles.
94  }
95 }
96
97 #endif
static PlueckerT CreateFromRay(const Vector3T< T > &A, const Vector3T< T > &Dir)
Creates a Pluecker coordinate from the ray that starts at (or "passes through") point A into directio...
Definition: Pluecker.hpp:55
This class represents Pluecker coordinates.
Definition: Pluecker.hpp:22
PlueckerT()
The default constructor.
Definition: Pluecker.hpp:27
T y
The y-component of this vector.
Definition: Vector3.hpp:41
This class represents a polymorphic 3-dimensional vector.
Definition: Misc.hpp:11
T p
The six components of the Pluecker coordinate.
Definition: Pluecker.hpp:85
T & operator[](unsigned long i)
Returns the i-th component of this Pluecker coordinate.
Definition: Pluecker.hpp:67
T operator*(const PlueckerT &Other) const
This operator computes the permuted inner product (as described in Tellers dissertation) of the two P...
Definition: Pluecker.hpp:73
static PlueckerT CreateFromLine(const Vector3T< T > &A, const Vector3T< T > &B)
Creates a Pluecker coordinate from the line (segment) that starts at point A and ends at point B...
Definition: Pluecker.hpp:44
T z
The z-component of this vector.
Definition: Vector3.hpp:42
PlueckerT(const T p0, const T p1, const T p2, const T p3, const T p4, const T p5)
Constructor for creating a Pluecker coordinate from individual components.
Definition: Pluecker.hpp:33
T x
The x-component of this vector.
Definition: Vector3.hpp:40