Fix issue in Rocket.lua script.
[Cafu-Engine.git] / Libs / Math3D / Pluecker.hpp
blob09da9b487379b5c67417b4bec21dc66e9e128ae1
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
7 #ifndef CAFU_MATH_PLUECKER_HPP_INCLUDED
8 #define CAFU_MATH_PLUECKER_HPP_INCLUDED
10 #include "Vector3.hpp"
11 #include <cassert>
14 namespace cf
16 namespace math
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
24 public:
26 /// The default constructor.
27 PlueckerT()
29 p[0]=p[1]=p[2]=p[3]=p[4]=p[5]=0;
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)
35 p[0]=p0;
36 p[1]=p1;
37 p[2]=p2;
38 p[3]=p3;
39 p[4]=p4;
40 p[5]=p5;
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)
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);
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)
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);
66 /// Returns the i-th component of this Pluecker coordinate.
67 T& operator [] (unsigned long i) { assert(i<6); return p[i]; }
69 /// Returns the i-th component of this Pluecker coordinate.
70 const T& operator [] (unsigned long i) const { assert(i<6); return p[i]; }
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
75 return p[0]*Other.p[4] + p[1]*Other.p[5] + p[2]*Other.p[3] + p[4]*Other.p[0] + p[5]*Other.p[1] + p[3]*Other.p[2];
79 // GetLine() const;
80 // GetRay() const;
81 // GetDir() const;
84 /// The six components of the Pluecker coordinate.
85 T p[6];
89 /// Typedef for an PlueckerT of floats.
90 typedef PlueckerT<float> PlueckerfT;
92 /// Typedef for an Pluecker of doubles.
93 typedef PlueckerT<double> PlueckerdT;
97 #endif