CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Geometry/Plane3D.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: Plane3D.h,v 1.5 2010/06/16 16:21:27 garren Exp $
3 // ---------------------------------------------------------------------------
4 //
5 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
6 //
7 // History:
8 // 22.09.96 E.Chernyaev - initial version
9 // 19.10.96 J.Allison - added == and <<.
10 // 15.04.03 E.Chernyaev - CLHEP-1.9: template version
11 
12 #ifndef HEP_PLANE3D_H
13 #define HEP_PLANE3D_H
14 
15 #include <iosfwd>
16 #include "CLHEP/Geometry/defs.h"
17 #include "CLHEP/Geometry/Point3D.h"
20 
21 namespace HepGeom {
22 
29  template<class T>
30  class Plane3D {
31  protected:
32  T a_, b_, c_, d_;
33 
34  public:
37  Plane3D() : a_(0.), b_(0.), c_(1.), d_(0.) {}
38 
41  Plane3D(T a1, T b1, T c1, T d1) : a_(a1), b_(b1), c_(c1), d_(d1) {}
42 
45  Plane3D(const Normal3D<T> & n, const Point3D<T> & p)
46  : a_(n.x()), b_(n.y()), c_(n.z()), d_(-n*p) {}
47 
50  Plane3D(const Point3D<T> & p1,
51  const Point3D<T> & p2,
52  const Point3D<T> & p3) {
53  Normal3D<T> n = (p2-p1).cross(p3-p1);
54  a_ = n.x(); b_ = n.y(); c_ = n.z(); d_ = -n*p1;
55  }
56 
64  : a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_) {}
65 
68  ~Plane3D() {};
69 
73  a_ = p.a_; b_ = p.b_; c_ = p.c_; d_ = p.d_; return *this;
74  }
75 
78  T a() const { return a_; }
81  T b() const { return b_; }
84  T c() const { return c_; }
87  T d() const { return d_; }
88 
91  Normal3D<T> normal() const { return Normal3D<T>(a_,b_,c_); }
92 
96  double ll = std::sqrt(a_*a_ + b_*b_ + c_*c_);
97  if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /= ll, d_ /= ll; }
98  return *this;
99  }
100 
103  T distance(const Point3D<T> & p) const {
104  return a()*p.x() + b()*p.y() + c()*p.z() + d();
105  }
106 
109  Point3D<T> point(const Point3D<T> & p) const {
110  T k = distance(p)/(a()*a()+b()*b()+c()*c());
111  return Point3D<T>(p.x()-a()*k, p.y()-b()*k, p.z()-c()*k);
112  }
113 
116  Point3D<T> point() const {
117  T k = -d()/(a()*a()+b()*b()+c()*c());
118  return Point3D<T>(a()*k, b()*k, c()*k);
119  }
120 
123  bool operator == (const Plane3D<T> & p) const {
124  return a() == p.a() && b() == p.b() && c() == p.c() && d() == p.d();
125  }
126 
129  bool operator != (const Plane3D<T> & p) const {
130  return a() != p.a() || b() != p.b() || c() != p.c() || d() != p.d();
131  }
132 
136  Normal3D<T> n = normal();
137  n.transform(m);
138  d_ = -n*point().transform(m); a_ = n.x(); b_ = n.y(); c_ = n.z();
139  return *this;
140  }
141  };
142 
147  std::ostream & operator<<(std::ostream & os, const Plane3D<float> & p);
148 
153  std::ostream & operator<<(std::ostream & os, const Plane3D<double> & p);
154 
155 } /* namespace HepGeom */
156 
157 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
158 // backwards compatibility will be enabled ONLY in CLHEP 1.9
159 typedef HepGeom::Plane3D<double> HepPlane3D;
160 #endif
161 
162 #endif /* HEP_PLANE3D_H */