Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plane3D.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id:$
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/Point3D.h"
19 
20 namespace HepGeom {
21 
28  template<class T>
29  class Plane3D {
30  protected:
31  T a_, b_, c_, d_;
32 
33  public:
36  Plane3D() : a_(0.), b_(0.), c_(1.), d_(0.) {}
37 
40  Plane3D(T a1, T b1, T c1, T d1) : a_(a1), b_(b1), c_(c1), d_(d1) {}
41 
44  Plane3D(const Normal3D<T> & n, const Point3D<T> & p)
45  : a_(n.x()), b_(n.y()), c_(n.z()), d_(-n*p) {}
46 
49  Plane3D(const Point3D<T> & p1,
50  const Point3D<T> & p2,
51  const Point3D<T> & p3) {
52  Normal3D<T> n = (p2-p1).cross(p3-p1);
53  a_ = n.x(); b_ = n.y(); c_ = n.z(); d_ = -n*p1;
54  }
55 
63  : a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_) {}
64 
67  ~Plane3D() {};
68 
72  a_ = p.a_; b_ = p.b_; c_ = p.c_; d_ = p.d_; return *this;
73  }
74 
77  T a() const { return a_; }
80  T b() const { return b_; }
83  T c() const { return c_; }
86  T d() const { return d_; }
87 
90  Normal3D<T> normal() const { return Normal3D<T>(a_,b_,c_); }
91 
95  double ll = std::sqrt(a_*a_ + b_*b_ + c_*c_);
96  if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /= ll, d_ /= ll; }
97  return *this;
98  }
99 
102  T distance(const Point3D<T> & p) const {
103  return a()*p.x() + b()*p.y() + c()*p.z() + d();
104  }
105 
108  Point3D<T> point(const Point3D<T> & p) const {
109  T k = distance(p)/(a()*a()+b()*b()+c()*c());
110  return Point3D<T>(p.x()-a()*k, p.y()-b()*k, p.z()-c()*k);
111  }
112 
115  Point3D<T> point() const {
116  T k = -d()/(a()*a()+b()*b()+c()*c());
117  return Point3D<T>(a()*k, b()*k, c()*k);
118  }
119 
122  bool operator == (const Plane3D<T> & p) const {
123  return a() == p.a() && b() == p.b() && c() == p.c() && d() == p.d();
124  }
125 
128  bool operator != (const Plane3D<T> & p) const {
129  return a() != p.a() || b() != p.b() || c() != p.c() || d() != p.d();
130  }
131 
135  Normal3D<T> n = normal();
136  n.transform(m);
137  d_ = -n*point().transform(m); a_ = n.x(); b_ = n.y(); c_ = n.z();
138  return *this;
139  }
140  };
141 
146  std::ostream & operator<<(std::ostream & os, const Plane3D<float> & p);
147 
152  std::ostream & operator<<(std::ostream & os, const Plane3D<double> & p);
153 
154 } /* namespace HepGeom */
155 
156 #endif /* HEP_PLANE3D_H */
T c() const
Definition: Plane3D.h:83
const char * p
Definition: xmltok.h:285
bool operator==(const Plane3D< T > &p) const
Definition: Plane3D.h:122
Normal3D< T > normal() const
Definition: Plane3D.h:90
tuple x
Definition: test.py:50
T d() const
Definition: Plane3D.h:86
Plane3D(const Normal3D< T > &n, const Point3D< T > &p)
Definition: Plane3D.h:44
static constexpr double m
Definition: G4SIunits.hh:129
const G4int n
Point3D< T > point(const Point3D< T > &p) const
Definition: Plane3D.h:108
static const G4double d1
Plane3D(const Point3D< T > &p1, const Point3D< T > &p2, const Point3D< T > &p3)
Definition: Plane3D.h:49
bool operator!=(const Plane3D< T > &p) const
Definition: Plane3D.h:128
Plane3D< T > & operator=(const Plane3D< T > &p)
Definition: Plane3D.h:71
tuple z
Definition: test.py:28
T a() const
Definition: Plane3D.h:77
Plane3D< T > & normalize()
Definition: Plane3D.h:94
Plane3D(T a1, T b1, T c1, T d1)
Definition: Plane3D.h:40
Plane3D< T > & transform(const Transform3D &m)
Definition: Plane3D.h:134
Point3D< T > point() const
Definition: Plane3D.h:115
T distance(const Point3D< T > &p) const
Definition: Plane3D.h:102
T b() const
Definition: Plane3D.h:80
tuple c1
Definition: plottest35.py:14
Plane3D(const Plane3D< float > &p)
Definition: Plane3D.h:62