Plane3D.cxx

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: Plane3D.cxx 32627 2010-03-16 17:53:54Z moneta $
00002 // Authors: W. Brown, M. Fischler, L. Moneta    2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 , LCG ROOT MathLib Team                         *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // implementation file for class Plane3D
00012 // 
00013 // Created by: Lorenzo Moneta  December 2 2005
00014 // 
00015 // 
00016 
00017 #include "Math/GenVector/Plane3D.h"
00018 
00019 #include <cmath>
00020 
00021 
00022 
00023 
00024 namespace ROOT {
00025 
00026 namespace Math {
00027 
00028 
00029 typedef Plane3D::Scalar Scalar; 
00030 typedef Plane3D::Point  XYZPoint; 
00031 typedef Plane3D::Vector XYZVector; 
00032 
00033 // ========== Constructors and Assignment =====================
00034 
00035 
00036 // constructor from 4 scalars numbers (a,b,c,d)
00037 Plane3D::Plane3D(const Scalar & a, const Scalar & b, const Scalar & c, const Scalar & d) : 
00038    fA(a), fB(b), fC(c), fD(d) 
00039 {
00040    //renormalize a,b,c to unit 
00041    Normalize();
00042 }
00043 
00044 // internal method to construct from a normal vector and a point
00045 void Plane3D::BuildFromVecAndPoint(const XYZVector & n, const XYZPoint & p ) 
00046 {
00047    // build from a normal vector and a point 
00048    fA =  n.X(); 
00049    fB =  n.Y(); 
00050    fC =  n.Z(); 
00051    fD = - n.Dot(p);
00052    Normalize();      
00053 }
00054 
00055 // internl method to construct from three points
00056 void Plane3D::BuildFrom3Points( const XYZPoint & p1, const XYZPoint & p2, const XYZPoint & p3 ) {
00057    
00058    // plane from thre points
00059    // normal is (x3-x1) cross (x2 -x1) 
00060    XYZVector n = (p2-p1).Cross(p3-p1);
00061    fA = n.X(); 
00062    fB = n.Y();
00063    fC = n.Z();
00064    fD = - n.Dot(p1);
00065    Normalize();
00066 }
00067 
00068 // distance plane- point
00069 Scalar Plane3D::Distance(const XYZPoint & p) const { 
00070    return fA*p.X() + fB*p.Y() + fC*p.Z() + fD; 
00071 }
00072 
00073 void Plane3D::Normalize() { 
00074    // normalize the plane 
00075    Scalar s = std::sqrt( fA*fA + fB*fB + fC*fC );
00076    // what to do if s = 0 ??
00077    if ( s == 0) { fD = 0; return; }
00078    Scalar w = 1./s;
00079    fA *= w; 
00080    fB *= w;
00081    fC *= w;
00082    fD *= w; 
00083 }
00084 
00085 
00086 // projection of a point onto the plane
00087 XYZPoint Plane3D::ProjectOntoPlane(const XYZPoint & p) const { 
00088    Scalar d = Distance(p); 
00089    return XYZPoint( p.X() - fA*d, p.Y() - fB*d, p.Z() - fC*d); 
00090 }
00091 
00092 
00093 // output 
00094 std::ostream & operator<< (std::ostream & os, const Plane3D & p) { 
00095    os << "\n" << p.Normal().X() 
00096    << "  " << p.Normal().Y() 
00097    << "  " << p.Normal().Z() 
00098    << "  " << p.HesseDistance() 
00099    << "\n";
00100    return os;
00101 }
00102 
00103  
00104 
00105  
00106 
00107 }  // end namespace Math
00108 }  // end namespace ROOT
00109 

Generated on Tue Jul 5 14:33:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1