Logo ROOT   6.08/07
Reference Guide
Plane3D.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: L. Moneta 12/2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 , LCG ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class LorentzVector
12 //
13 // Created by: moneta at Fri Dec 02 2005
14 //
15 // Last update: $Id$
16 //
17 #ifndef ROOT_Math_GenVector_Plane3D
18 #define ROOT_Math_GenVector_Plane3D 1
19 
22 
23 
24 
25 namespace ROOT {
26 
27 namespace Math {
28 
29 
30 
31 //_______________________________________________________________________________
32  /**
33  Class describing a geometrical plane in 3 dimensions.
34  A Plane3D is a 2 dimensional surface spanned by two linearly independent vectors.
35  The plane is described by the equation
36  \f$ a*x + b*y + c*z + d = 0 \f$ where (a,b,c) are the components of the
37  normal vector to the plane \f$ n = (a,b,c) \f$ and \f$ d = - n \dot x \f$, where x is any point
38  belonging to plane.
39  More information on the mathematics describing a plane in 3D is available on
40  <A HREF=http://mathworld.wolfram.com/Plane.html>MathWord</A>.
41  The Plane3D class contains the 4 scalar values in double which represent the
42  four coefficients, fA, fB, fC, fD. fA, fB, fC are the normal components normalized to 1,
43  i.e. fA**2 + fB**2 + fC**2 = 1
44 
45  @ingroup GenVector
46  */
47  class Plane3D {
48 
49  public:
50 
51  // ------ ctors ------
52 
53  typedef double Scalar;
54 
57 
58 
59 
60  /**
61  default constructor create plane z = 0
62  */
63  Plane3D ( ) : fA(0), fB(0), fC(1.), fD(0) { }
64 
65  /**
66  generic constructors from the four scalar values describing the plane
67  according to the equation ax + by + cz + d = 0
68  \param a scalar value
69  \param b scalar value
70  \param c scalar value
71  \param d sxcalar value
72  */
73  Plane3D(const Scalar & a, const Scalar & b, const Scalar & c, const Scalar & d);
74 
75  /**
76  constructor a Plane3D from a normal vector and a point coplanar to the plane
77  \param n normal expressed as a ROOT::Math::DisplacementVector3D<Cartesian3D<double> >
78  \param p point expressed as a ROOT::Math::PositionVector3D<Cartesian3D<double> >
79  */
80  Plane3D(const Vector & n, const Point & p )
81  {
82  BuildFromVecAndPoint( n, p );
83  }
84 
85 
86  /**
87  Construct from a generic DisplacementVector3D (normal vector) and PositionVector3D (point coplanar to
88  the plane)
89  \param n normal expressed as a generic ROOT::Math::DisplacementVector3D
90  \param p point expressed as a generic ROOT::Math::PositionVector3D
91  */
92  template<class T1, class T2, class U>
94  {
96  }
97 
98  /**
99  constructor from three Cartesian point belonging to the plane
100  \param p1 point1 expressed as a generic ROOT::Math::PositionVector3D
101  \param p2 point2 expressed as a generic ROOT::Math::PositionVector3D
102  \param p3 point3 expressed as a generic ROOT::Math::PositionVector3D
103  */
104  Plane3D(const Point & p1, const Point & p2, const Point & p3 ) {
105  BuildFrom3Points(p1,p2,p3);
106  }
107 
108  /**
109  constructor from three generic point belonging to the plane
110  \param p1 point1 expressed as ROOT::Math::DisplacementVector3D<Cartesian3D<double> >
111  \param p2 point2 expressed as ROOT::Math::DisplacementVector3D<Cartesian3D<double> >
112  \param p3 point3 expressed as ROOT::Math::DisplacementVector3D<Cartesian3D<double> >
113  */
114  template <class T1, class T2, class T3, class U>
116  {
117  BuildFrom3Points( Point(p1.X(), p1.Y(), p1.Z()),
118  Point(p2.X(), p2.Y(), p2.Z()),
119  Point(p3.X(), p3.Y(), p3.Z()) );
120  }
121 
122 
123 
124  // compiler-generated copy ctor and dtor are fine.
125 
126  // ------ assignment ------
127 
128  /**
129  Assignment operator from other Plane3D class
130  */
131  Plane3D & operator= ( const Plane3D & plane) {
132  fA = plane.fA;
133  fB = plane.fB;
134  fC = plane.fC;
135  fD = plane.fD;
136  return *this;
137  }
138 
139  /**
140  Return the a coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the
141  x-component of the vector perpendicular to the plane.
142  */
143  Scalar A() const { return fA; }
144 
145  /**
146  Return the b coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the
147  y-component of the vector perpendicular to the plane
148  */
149  Scalar B() const { return fB; }
150 
151  /**
152  Return the c coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also the
153  z-component of the vector perpendicular to the plane
154  */
155  Scalar C() const { return fC; }
156 
157  /**
158  Return the d coefficient of the plane equation \f$ a*x + b*y + c*z + d = 0 \f$. It is also
159  the distance from the origin (HesseDistance)
160  */
161  Scalar D() const { return fD; }
162 
163  /**
164  Return normal vector to the plane as Cartesian DisplacementVector
165  */
166  Vector Normal() const {
167  return Vector(fA, fB, fC);
168  }
169 
170  /**
171  Return the Hesse Distance (distance from the origin) of the plane or
172  the d coefficient expressed in normalize form
173  */
174  Scalar HesseDistance() const {
175  return fD;
176  }
177 
178 
179  /**
180  Return the signed distance to a Point.
181  The distance is signed positive if the Point is in the same side of the
182  normal vector to the plane.
183  \param p Point expressed in Cartesian Coordinates
184  */
185  Scalar Distance(const Point & p) const;
186 
187  /**
188  Return the distance to a Point described with generic coordinates
189  \param p Point expressed as generic ROOT::Math::PositionVector3D
190  */
191  template <class T, class U>
192  Scalar Distance(const PositionVector3D<T,U> & p) const {
193  return Distance( Point(p.X(), p.Y(), p.Z() ) );
194  }
195 
196  /**
197  Return the projection of a Cartesian point to a plane
198  \param p Point expressed as PositionVector3D<Cartesian3D<double> >
199  */
200  Point ProjectOntoPlane(const Point & p) const;
201 
202  /**
203  Return the projection of a point to a plane
204  \param p Point expressed as generic ROOT::Math::PositionVector3D
205  */
206  template <class T, class U>
208  Point pxyz = ProjectOntoPlane(Point(p.X(), p.Y(), p.Z() ) );
210  p2.SetXYZ( pxyz.X(), pxyz.Y(), pxyz.Z() );
211  return p2;
212  }
213 
214 
215 
216  // ------------------- Equality -----------------
217 
218  /**
219  Exact equality
220  */
221  bool operator==(const Plane3D & rhs) const {
222  return fA == rhs.fA && fB == rhs.fB && fC == rhs.fC && fD == rhs.fD;
223  }
224  bool operator!= (const Plane3D & rhs) const {
225  return !(operator==(rhs));
226  }
227 
228  protected:
229 
230  /**
231  Normalize the normal (a,b,c) plane components
232  */
233  void Normalize();
234 
235 
236  private:
237 
238  // internal method to construct class from a vector and a point
239  void BuildFromVecAndPoint(const Vector & n, const Point & p);
240  // internal method to construct class from 3 points
241  void BuildFrom3Points(const Point & p1, const Point & p2, const Point & p3);
242 
243  // plane data members the four scalar which satisfies fA*x + fB*y + fC*z + fD = 0
244  // for every point (x,y,z) belonging to the plane.
245  // fA**2 + fB**2 + fC** =1 plane is stored in normalized form
246  Scalar fA;
247  Scalar fB;
248  Scalar fC;
249  Scalar fD;
250 
251 
252  }; // Plane3D<>
253 
254  /**
255  Stream Output and Input
256  */
257  // TODO - I/O should be put in the manipulator form
258 
259  std::ostream & operator<< (std::ostream & os, const Plane3D & p);
260 
261 
262 } // end namespace Math
263 
264 } // end namespace ROOT
265 
266 
267 #endif
268 
269 
270 
271 
Class describing a geometrical plane in 3 dimensions.
Definition: Plane3D.h:47
static double p3(double t, double a, double b, double c, double d)
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
Scalar B() const
Return the b coefficient of the plane equation .
Definition: Plane3D.h:149
Plane3D()
default constructor create plane z = 0
Definition: Plane3D.h:63
return c
Scalar Distance(const Point &p) const
Return the signed distance to a Point.
Definition: Plane3D.cxx:69
bool operator==(const Plane3D &rhs) const
Exact equality.
Definition: Plane3D.h:221
Class describing a generic position vector (point) in 3 dimensions.
TArc * a
Definition: textangle.C:12
Scalar Distance(const PositionVector3D< T, U > &p) const
Return the distance to a Point described with generic coordinates.
Definition: Plane3D.h:192
Scalar A() const
Return the a coefficient of the plane equation .
Definition: Plane3D.h:143
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
Scalar D() const
Return the d coefficient of the plane equation .
Definition: Plane3D.h:161
Plane3D & operator=(const Plane3D &plane)
Assignment operator from other Plane3D class.
Definition: Plane3D.h:131
PositionVector3D< T, U > ProjectOntoPlane(const PositionVector3D< T, U > &p) const
Return the projection of a point to a plane.
Definition: Plane3D.h:207
static double p2(double t, double a, double b, double c)
Plane3D(const DisplacementVector3D< T1, U > &n, const PositionVector3D< T2, U > &p)
Construct from a generic DisplacementVector3D (normal vector) and PositionVector3D (point coplanar to...
Definition: Plane3D.h:93
Scalar C() const
Return the c coefficient of the plane equation .
Definition: Plane3D.h:155
Plane3D(const Vector &n, const Point &p)
constructor a Plane3D from a normal vector and a point coplanar to the plane
Definition: Plane3D.h:80
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Definition: Plane3D.h:166
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Class describing a generic displacement vector in 3 dimensions.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Point
Definition: Plane3D.h:56
Scalar HesseDistance() const
Return the Hesse Distance (distance from the origin) of the plane or the d coefficient expressed in n...
Definition: Plane3D.h:174
static double p1(double t, double a, double b)
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Vector
Definition: Plane3D.h:55
void BuildFromVecAndPoint(const Vector &n, const Point &p)
Definition: Plane3D.cxx:45
void Normalize()
Normalize the normal (a,b,c) plane components.
Definition: Plane3D.cxx:73
Plane3D(const PositionVector3D< T1, U > &p1, const PositionVector3D< T2, U > &p2, const PositionVector3D< T3, U > &p3)
constructor from three generic point belonging to the plane
Definition: Plane3D.h:115
Namespace for new Math classes and functions.
void BuildFrom3Points(const Point &p1, const Point &p2, const Point &p3)
Definition: Plane3D.cxx:56
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
PositionVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
bool operator!=(const Plane3D &rhs) const
Definition: Plane3D.h:224
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Plane3D(const Point &p1, const Point &p2, const Point &p3)
constructor from three Cartesian point belonging to the plane
Definition: Plane3D.h:104
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
const Int_t n
Definition: legend1.C:16
Point ProjectOntoPlane(const Point &p) const
Return the projection of a Cartesian point to a plane.
Definition: Plane3D.cxx:87