CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: Plane3D.h,v 1.5 2010/06/16 16:21:27 garren Exp $ 00003 // --------------------------------------------------------------------------- 00004 // 00005 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 00006 // 00007 // History: 00008 // 22.09.96 E.Chernyaev - initial version 00009 // 19.10.96 J.Allison - added == and <<. 00010 // 15.04.03 E.Chernyaev - CLHEP-1.9: template version 00011 00012 #ifndef HEP_PLANE3D_H 00013 #define HEP_PLANE3D_H 00014 00015 #include <iosfwd> 00016 #include "CLHEP/Geometry/defs.h" 00017 #include "CLHEP/Geometry/Point3D.h" 00018 #include "CLHEP/Geometry/Normal3D.h" 00019 #include "CLHEP/Geometry/Transform3D.h" 00020 00021 namespace HepGeom { 00022 00029 template<class T> 00030 class Plane3D { 00031 protected: 00032 T a_, b_, c_, d_; 00033 00034 public: 00037 Plane3D() : a_(0.), b_(0.), c_(1.), d_(0.) {} 00038 00041 Plane3D(T a1, T b1, T c1, T d1) : a_(a1), b_(b1), c_(c1), d_(d1) {} 00042 00045 Plane3D(const Normal3D<T> & n, const Point3D<T> & p) 00046 : a_(n.x()), b_(n.y()), c_(n.z()), d_(-n*p) {} 00047 00050 Plane3D(const Point3D<T> & p1, 00051 const Point3D<T> & p2, 00052 const Point3D<T> & p3) { 00053 Normal3D<T> n = (p2-p1).cross(p3-p1); 00054 a_ = n.x(); b_ = n.y(); c_ = n.z(); d_ = -n*p1; 00055 } 00056 00063 Plane3D(const Plane3D<float> & p) 00064 : a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_) {} 00065 00068 ~Plane3D() {}; 00069 00072 Plane3D<T> & operator=(const Plane3D<T> & p) { 00073 a_ = p.a_; b_ = p.b_; c_ = p.c_; d_ = p.d_; return *this; 00074 } 00075 00078 T a() const { return a_; } 00081 T b() const { return b_; } 00084 T c() const { return c_; } 00087 T d() const { return d_; } 00088 00091 Normal3D<T> normal() const { return Normal3D<T>(a_,b_,c_); } 00092 00095 Plane3D<T> & normalize() { 00096 double ll = std::sqrt(a_*a_ + b_*b_ + c_*c_); 00097 if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /= ll, d_ /= ll; } 00098 return *this; 00099 } 00100 00103 T distance(const Point3D<T> & p) const { 00104 return a()*p.x() + b()*p.y() + c()*p.z() + d(); 00105 } 00106 00109 Point3D<T> point(const Point3D<T> & p) const { 00110 T k = distance(p)/(a()*a()+b()*b()+c()*c()); 00111 return Point3D<T>(p.x()-a()*k, p.y()-b()*k, p.z()-c()*k); 00112 } 00113 00116 Point3D<T> point() const { 00117 T k = -d()/(a()*a()+b()*b()+c()*c()); 00118 return Point3D<T>(a()*k, b()*k, c()*k); 00119 } 00120 00123 bool operator == (const Plane3D<T> & p) const { 00124 return a() == p.a() && b() == p.b() && c() == p.c() && d() == p.d(); 00125 } 00126 00129 bool operator != (const Plane3D<T> & p) const { 00130 return a() != p.a() || b() != p.b() || c() != p.c() || d() != p.d(); 00131 } 00132 00135 Plane3D<T> & transform(const Transform3D & m) { 00136 Normal3D<T> n = normal(); 00137 n.transform(m); 00138 d_ = -n*point().transform(m); a_ = n.x(); b_ = n.y(); c_ = n.z(); 00139 return *this; 00140 } 00141 }; 00142 00147 std::ostream & operator<<(std::ostream & os, const Plane3D<float> & p); 00148 00153 std::ostream & operator<<(std::ostream & os, const Plane3D<double> & p); 00154 00155 } /* namespace HepGeom */ 00156 00157 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00158 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00159 typedef HepGeom::Plane3D<double> HepPlane3D; 00160 #endif 00161 00162 #endif /* HEP_PLANE3D_H */