CLHEP/Geometry/Plane3D.h
// -*- C++ -*-
// $Id: Plane3D.h,v 1.12 2001/06/15 07:30:41 evc Exp $
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// Hep geometrical 3D Plane class
//
// Author: Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
//
// History:
// 22.09.96 E.Chernyaev - initial version
// 19.10.96 J.Allison - added == and <<.
#ifndef HEP_PLANE3D_H
#define HEP_PLANE3D_H
#include "CLHEP/Geometry/Point3D.h"
#include "CLHEP/Geometry/Normal3D.h"
#include "CLHEP/config/iostream.h"
class HepPlane3D {
protected:
HepDouble aa, bb, cc, dd;
public:
// Constructors
HepPlane3D(HepDouble a=0, HepDouble b=0, HepDouble c=0, HepDouble d=0)
: aa(a), bb(b), cc(c), dd(d) {}
HepPlane3D(const HepNormal3D &n, const HepPoint3D &p)
: aa(n.x()), bb(n.y()), cc(n.z()), dd(-n*p) {}
HepPlane3D(const HepPoint3D &p1, const HepPoint3D &p2, const HepPoint3D &p3) {
HepNormal3D n = (p2-p1).cross(p3-p1);
aa = n.x(); bb = n.y(); cc = n.z(); dd = -n*p1;
}
// Copy constructor
HepPlane3D(const HepPlane3D &plane)
: aa(plane.aa), bb(plane.bb), cc(plane.cc), dd(plane.dd) {}
// Destructor
~HepPlane3D() {};
// Assignment
HepPlane3D& operator=(const HepPlane3D &plane) {
aa = plane.aa; bb = plane.bb; cc = plane.cc; dd = plane.dd; return *this;
}
// Test for equality
HepBoolean operator == (const HepPlane3D& p) const {
return aa == p.aa && bb == p.bb && cc == p.cc && dd == p.dd;
}
// Test for inequality
HepBoolean operator != (const HepPlane3D& p) const {
return aa != p.aa || bb != p.bb || cc != p.cc || dd != p.dd;
}
// Normalization
HepPlane3D& normalize() {
HepDouble ll = sqrt(aa*aa + bb*bb + cc*cc);
if (ll > 0.0) { aa /= ll; bb /= ll; cc /= ll, dd /= ll; }
return *this;
}
// Access functions
HepDouble a() const { return aa; }
HepDouble b() const { return bb; }
HepDouble c() const { return cc; }
HepDouble d() const { return dd; }
// Return normal
HepNormal3D normal() const { return HepNormal3D(aa,bb,cc); }
// Return distance from the point
HepDouble distance(const HepPoint3D &p) const {
return aa*p.x() + bb*p.y() + cc*p.z() + dd;
}
// Projection of the point to the plane
HepPoint3D point(const HepPoint3D &p) const {
HepDouble k = distance(p)/(aa*aa+bb*bb+cc*cc);
return HepPoint3D(p.x()-aa*k, p.y()-bb*k, p.z()-cc*k);
}
// Projection of the origin to the plane
HepPoint3D point() const {
HepDouble k = -dd/(aa*aa+bb*bb+cc*cc);
return HepPoint3D(aa*k, bb*k, cc*k);
}
// Transformation
HepPlane3D& transform(const HepTransform3D &m) {
HepNormal3D n(aa,bb,cc);
n.transform(m);
dd = -n*point().transform(m); aa = n.x(); bb = n.y(); cc = n.z();
return *this;
}
};
HepStd::ostream & operator << (HepStd::ostream &, const HepPlane3D &);
#endif /* HEP_PLANE3D_H */
Generated by GNU enscript 1.6.1.