ROOT  6.06/09
Reference Guide
Plane3D.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: W. Brown, M. Fischler, L. Moneta 2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 , LCG ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // implementation file for class Plane3D
12 //
13 // Created by: Lorenzo Moneta December 2 2005
14 //
15 //
16 
17 #include "Math/GenVector/Plane3D.h"
18 
19 #include <cmath>
20 
21 
22 
23 
24 namespace ROOT {
25 
26 namespace Math {
27 
28 
30 typedef Plane3D::Point XYZPoint;
32 
33 // ========== Constructors and Assignment =====================
34 
35 
36 // constructor from 4 scalars numbers (a,b,c,d)
37 Plane3D::Plane3D(const Scalar & a, const Scalar & b, const Scalar & c, const Scalar & d) :
38  fA(a), fB(b), fC(c), fD(d)
39 {
40  //renormalize a,b,c to unit
41  Normalize();
42 }
43 
44 // internal method to construct from a normal vector and a point
45 void Plane3D::BuildFromVecAndPoint(const XYZVector & n, const XYZPoint & p )
46 {
47  // build from a normal vector and a point
48  fA = n.X();
49  fB = n.Y();
50  fC = n.Z();
51  fD = - n.Dot(p);
52  Normalize();
53 }
54 
55 // internl method to construct from three points
56 void Plane3D::BuildFrom3Points( const XYZPoint & p1, const XYZPoint & p2, const XYZPoint & p3 ) {
57 
58  // plane from thre points
59  // normal is (x3-x1) cross (x2 -x1)
60  XYZVector n = (p2-p1).Cross(p3-p1);
61  fA = n.X();
62  fB = n.Y();
63  fC = n.Z();
64  fD = - n.Dot(p1);
65  Normalize();
66 }
67 
68 // distance plane- point
69 Scalar Plane3D::Distance(const XYZPoint & p) const {
70  return fA*p.X() + fB*p.Y() + fC*p.Z() + fD;
71 }
72 
74  // normalize the plane
75  Scalar s = std::sqrt( fA*fA + fB*fB + fC*fC );
76  // what to do if s = 0 ??
77  if ( s == 0) { fD = 0; return; }
78  Scalar w = 1./s;
79  fA *= w;
80  fB *= w;
81  fC *= w;
82  fD *= w;
83 }
84 
85 
86 // projection of a point onto the plane
87 XYZPoint Plane3D::ProjectOntoPlane(const XYZPoint & p) const {
88  Scalar d = Distance(p);
89  return XYZPoint( p.X() - fA*d, p.Y() - fB*d, p.Z() - fC*d);
90 }
91 
92 
93 // output
94 std::ostream & operator<< (std::ostream & os, const Plane3D & p) {
95  os << "\n" << p.Normal().X()
96  << " " << p.Normal().Y()
97  << " " << p.Normal().Z()
98  << " " << p.HesseDistance()
99  << "\n";
100  return os;
101 }
102 
103 
104 
105 
106 
107 } // end namespace Math
108 } // end namespace ROOT
109 
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)
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Plane3D()
default constructor create plane z = 0
Definition: Plane3D.h:63
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZPoint
3D Point based on the cartesian coordinates x,y,z in double precision
Definition: Point3Dfwd.h:33
Class describing a generic position vector (point) in 3 dimensions.
TArc * a
Definition: textangle.C:12
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
double sqrt(double)
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Definition: Plane3D.h:166
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
static double p2(double t, double a, double b, double c)
Point ProjectOntoPlane(const Point &p) const
Return the projection of a Cartesian point to a plane.
Definition: Plane3D.cxx:87
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)
SVector< T, 3 > Cross(const SVector< T, 3 > &lhs, const SVector< T, 3 > &rhs)
Vector Cross Product (only for 3-dim vectors) .
Definition: Functions.h:324
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
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Definition: Vector3Dfwd.h:34
Namespace for new Math classes and functions.
void BuildFrom3Points(const Point &p1, const Point &p2, const Point &p3)
Definition: Plane3D.cxx:56
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Distance(const Point &p) const
Return the signed distance to a Point.
Definition: Plane3D.cxx:69
Plane3D::Scalar Scalar
Definition: Plane3D.cxx:29
const Int_t n
Definition: legend1.C:16