00001 #ifndef _GEOM_PLANE3D_HPP
00002 #define _GEOM_PLANE3D_HPP
00003
00004 #include "geom/HyperPlane.hpp"
00005 #include "geom/Repere.hpp"
00006 #include "jmath/ublasExtra.hpp"
00007
00008 namespace jafar {
00009 namespace geom {
00010 class Plane3D : public HyperPlane<3> {
00011 public:
00012 class PointsDriver : public HyperPlane<3>::EquationDriver {
00013 public:
00017 PointsDriver(const VecD& p1, const VecD& p2, const VecD& p3,
00018 const RepereD* reference = Repere3D::global())
00019 {
00020 VecD p1p2 = p2 - p1;
00021 VecD p1p3 = p3 - p1;
00022
00023 VecD n; jmath::ublasExtra::crossProd(p1p2, p1p3, n);
00024 double norm = ublas::norm_2( n );
00025 m_eqn[3] = 0 - p1[0]*n[0] -p1[1]*n[1] - p1[2]*n[2];
00026 ublas::subrange(m_eqn, 0, 3 ) = n;
00027 m_eqn /= norm;
00028 m_n = m_eqn;
00029 m_n(3) = 0.0;
00030 }
00031 private:
00032 PointsDriver(const HomogenousVecD& eqn, const HomogenousVecD& n,
00033 const RepereD* reference = RepereD::global()) :
00034 HyperPlane<3>::EquationDriver(eqn, reference), m_n(n) {}
00035
00036 public:
00037 HomogenousVecD equation() const { return m_eqn; }
00038 HomogenousVecD origin()
00039 {
00040 HomogenousVecD origin = - m_eqn(3) * m_n;
00041 origin(3) = 1.0;
00042 return origin;
00043 }
00044 HomogenousVecD normal() const { return m_n; }
00045 virtual Driver* clone() const
00046 {
00047 return new PointsDriver(m_eqn, m_n, this->reference());
00048 }
00049
00050 private:
00051 HomogenousVecD m_n;
00052 };
00053 Plane3D(Driver* d) : HyperPlane<3>(d) {};
00054 Plane3D(const Plane3D &p) :
00055 HyperPlane<3>((HyperPlane<3>) p)
00056 {
00057 using namespace std;
00058 this->setDriver(p.m_driver->clone());
00059 }
00060 };
00061 }
00062 }
00063
00064 #endif