CLHEP 2.4.7.1
C++ Class Library for High Energy Physics
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"
20
21namespace 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
59 Plane3D(const Plane3D<T> &) = default;
60
63 template<typename U = T,
64 typename = typename std::enable_if<!std::is_same<U,float>::value >::type>
66 : a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_) {}
67
70 Plane3D(Plane3D<T> &&) = default;
71
74 ~Plane3D() = default;
75
78 Plane3D<T> & operator=(const Plane3D<T> &) = default;
79
83
86 T a() const { return a_; }
89 T b() const { return b_; }
92 T c() const { return c_; }
95 T d() const { return d_; }
96
99 Normal3D<T> normal() const { return Normal3D<T>(a_,b_,c_); }
100
104 double ll = std::sqrt(a_*a_ + b_*b_ + c_*c_);
105 if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /= ll, d_ /= ll; }
106 return *this;
107 }
108
111 T distance(const Point3D<T> & p) const {
112 return a()*p.x() + b()*p.y() + c()*p.z() + d();
113 }
114
117 Point3D<T> point(const Point3D<T> & p) const {
118 T k = distance(p)/(a()*a()+b()*b()+c()*c());
119 return Point3D<T>(p.x()-a()*k, p.y()-b()*k, p.z()-c()*k);
120 }
121
125 T k = -d()/(a()*a()+b()*b()+c()*c());
126 return Point3D<T>(a()*k, b()*k, c()*k);
127 }
128
131 bool operator == (const Plane3D<T> & p) const {
132 return a() == p.a() && b() == p.b() && c() == p.c() && d() == p.d();
133 }
134
137 bool operator != (const Plane3D<T> & p) const {
138 return a() != p.a() || b() != p.b() || c() != p.c() || d() != p.d();
139 }
140
144 Normal3D<T> n = normal();
145 n.transform(m);
146 d_ = -n*point().transform(m); a_ = n.x(); b_ = n.y(); c_ = n.z();
147 return *this;
148 }
149 };
150
155 std::ostream & operator<<(std::ostream & os, const Plane3D<float> & p);
156
161 std::ostream & operator<<(std::ostream & os, const Plane3D<double> & p);
162
163} /* namespace HepGeom */
164
165#ifdef ENABLE_BACKWARDS_COMPATIBILITY
166// backwards compatibility will be enabled ONLY in CLHEP 1.9
167typedef HepGeom::Plane3D<double> HepPlane3D;
168#endif
169
170#endif /* HEP_PLANE3D_H */
Plane3D(T a1, T b1, T c1, T d1)
Definition Plane3D.h:41
Plane3D< T > & normalize()
Definition Plane3D.h:103
Plane3D(const Normal3D< T > &n, const Point3D< T > &p)
Definition Plane3D.h:45
Plane3D(Plane3D< T > &&)=default
T d() const
Definition Plane3D.h:95
T b() const
Definition Plane3D.h:89
T c() const
Definition Plane3D.h:92
T a() const
Definition Plane3D.h:86
Plane3D(const Plane3D< T > &)=default
Point3D< T > point(const Point3D< T > &p) const
Definition Plane3D.h:117
Plane3D(const Point3D< T > &p1, const Point3D< T > &p2, const Point3D< T > &p3)
Definition Plane3D.h:50
Plane3D< T > & operator=(const Plane3D< T > &)=default
Plane3D< T > & operator=(Plane3D< T > &&)=default
Normal3D< T > normal() const
Definition Plane3D.h:99
Point3D< T > point() const
Definition Plane3D.h:124
Plane3D(const Plane3D< float > &p)
Definition Plane3D.h:65
~Plane3D()=default
T distance(const Point3D< T > &p) const
Definition Plane3D.h:111
std::ostream & operator<<(std::ostream &os, const Plane3D< float > &p)
bool operator!=(const Plane3D< T > &p) const
Definition Plane3D.h:137
bool operator==(const Plane3D< T > &p) const
Definition Plane3D.h:131
std::ostream & operator<<(std::ostream &os, const Plane3D< double > &p)
Plane3D< T > & transform(const Transform3D &m)
Definition Plane3D.h:143