ROOT logo

// from ROOT
#include "TMath.h"

// from hydra
#include "hkaldef.h"
#include "hkalgeomtools.h"
#include "hkalplane.h"

#include <iostream>
#include <iomanip>
using namespace std;

ClassImp(HKalPlane)

//_HADES_CLASS_DESCRIPTION
///////////////////////////////////////////////////////////////////////////////
//
// A class that implements a planar surface of infinite dimension. The plane
// is defined either by a point on the plane and its normal vector which is a unit
// vector or alternatively by a point and two perpendicular axis on the plane.
//
//-----------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////


//  -----------------------------------
//  Ctors and Dtor
//  -----------------------------------

HKalPlane::HKalPlane(const TVector3 &center, const TVector3 &normal) : TObject() {
    // Creates a plane defined by a point on the plane and its normal vector.
    // Hesse Normal Form: center * normal - d = 0
    // center: a point on the plane.
    // normal: normal vector of the plane.

    setPlane(center, normal);
}

HKalPlane::HKalPlane(const TVector3 &origin, const TVector3 &u, const TVector3 &v) : TObject() {
    // Creates a plane defined by two axis u and v on the plane defining its coordinate system
    // and the origin of the plane's coordinate system.

    setPlane(origin, u, v);
}

HKalPlane::~HKalPlane() {
}

//  -----------------------------------
//  Implementation of public methods
//  -----------------------------------

Double_t HKalPlane::distanceToPlane(const TVector3 &point) const {
    // Calculates the distance of vector pos to the plane.

    return HKalGeomTools::distancePointToPlane(point, getCenter(), getNormal());
}

Bool_t HKalPlane::findIntersection(TVector3 &pointIntersect, const TVector3 &pos, const TVector3 &dir) const {
    // Finds the intersection point of a straight line with this plane.
    // pointIntersect: the intersection point (return value).
    // t:              line parameter to reach the plane (return value)
    // pos:            a point on the straight line.
    // dir:            direction of the straight line.

    return HKalGeomTools::findIntersectionLinePlane(pointIntersect, pos, dir, getCenter(), getNormal());
}

Bool_t HKalPlane::isOnSurface(const TVector3 &point) const {
    // Checks if point is on the plane.

    return HKalGeomTools::isPointOnPlane(point, getCenter(), getNormal());
}

void HKalPlane::print(Option_t* opt) const {
    // Print center and normal vectors of this plane.
    // opt: print options (not used)

    cout<<"**** Properties of plane: ****"<<endl;
    cout<<"Center of layer: "<<endl;
    getCenter().Print();
    cout<<"Normal of layer:"<<endl;
    getNormal().Print();
    cout<<"Axis U:"<<endl;
    getAxisU().Print();
    cout<<"Axis V:"<<endl;
    getAxisV().Print();
    cout<<"**** End print of plane ****"<<endl;
}

Double_t HKalPlane::signedDistanceToPlane(const TVector3 &point) const {
    // Calculates the distance of vector pos to the plane.
    // The signed distance is positive if the origin of the coordinate system and the
    // test point are on opposite sides of the plane and negative if they are on the same side.

    return HKalGeomTools::signedDistancePointToPlane(point, getCenter(), getNormal());
}

void HKalPlane::transform(const TRotation &transMat) {
    // Transforms the plane using a rotation matrix.

    vCenter.Transform(transMat);
    vNormal.Transform(transMat);
    vAxisU .Transform(transMat);
    vAxisV .Transform(transMat);
}

Bool_t HKalPlane::setPlane(const TVector3 &origin, const TVector3 &normal) {
    // Set the plane using a point on the plane and the plane's normal vector.

#if kalDebug > 0
    if(normal.Mag() == 0.) {
	Error("setPlane()", "Normal vector of plane has length zero.");
        return kFALSE;
    }
#endif

    vCenter = origin;
    vNormal = normal.Unit();
    // Make sure the normal vector points from (0,0,0) to the plane.
    if(vCenter * vNormal < 0.) {
        vNormal *= -1.;
    }

    // Define two orthogonal axis u and v that lie in the plane.
    if(vNormal.X() != 0. && vNormal.Y() != 0.) {
	vAxisU.SetXYZ(-vNormal.Y(), vNormal.X(), 0.);
        vAxisU.SetMag(1.);
    } else {
	vAxisU.SetXYZ(1., 0., 0.); // Normal vector is parallel to z-Axis.
    }
    vAxisV  = vNormal.Cross(vAxisU);
    vAxisV.SetMag(1.);

    return kTRUE;
}

Bool_t HKalPlane::setPlane(const TVector3 &origin, const TVector3 &u, const TVector3 &v) {
    // Sets the two axis u and v on the plane defining its coordinate system
    // and the origin of the plane's coordinate system.

    Bool_t axisOrth = kTRUE;
    if(TMath::Abs(u * v) > 1.e-3) {
#if kalDebug > 0
	Double_t angle = u.Angle(v) * TMath::RadToDeg();
	Warning("setPlane()",
		Form("The plane's axis u and v are not orthogonal. The Angle between them is %f degrees.", angle));
#endif
        axisOrth = kFALSE;
    }

    vCenter = origin;
    vAxisU  = u.Unit();
    vAxisV  = v.Unit();
    vNormal = u.Cross(v);
    vNormal = vNormal.Unit();
    // Make sure the normal vector points from (0,0,0) to the plane.
    if(vCenter * vNormal < 0.) {
        vNormal *= -1.;
    }
    return axisOrth;
}
 hkalplane.cc:1
 hkalplane.cc:2
 hkalplane.cc:3
 hkalplane.cc:4
 hkalplane.cc:5
 hkalplane.cc:6
 hkalplane.cc:7
 hkalplane.cc:8
 hkalplane.cc:9
 hkalplane.cc:10
 hkalplane.cc:11
 hkalplane.cc:12
 hkalplane.cc:13
 hkalplane.cc:14
 hkalplane.cc:15
 hkalplane.cc:16
 hkalplane.cc:17
 hkalplane.cc:18
 hkalplane.cc:19
 hkalplane.cc:20
 hkalplane.cc:21
 hkalplane.cc:22
 hkalplane.cc:23
 hkalplane.cc:24
 hkalplane.cc:25
 hkalplane.cc:26
 hkalplane.cc:27
 hkalplane.cc:28
 hkalplane.cc:29
 hkalplane.cc:30
 hkalplane.cc:31
 hkalplane.cc:32
 hkalplane.cc:33
 hkalplane.cc:34
 hkalplane.cc:35
 hkalplane.cc:36
 hkalplane.cc:37
 hkalplane.cc:38
 hkalplane.cc:39
 hkalplane.cc:40
 hkalplane.cc:41
 hkalplane.cc:42
 hkalplane.cc:43
 hkalplane.cc:44
 hkalplane.cc:45
 hkalplane.cc:46
 hkalplane.cc:47
 hkalplane.cc:48
 hkalplane.cc:49
 hkalplane.cc:50
 hkalplane.cc:51
 hkalplane.cc:52
 hkalplane.cc:53
 hkalplane.cc:54
 hkalplane.cc:55
 hkalplane.cc:56
 hkalplane.cc:57
 hkalplane.cc:58
 hkalplane.cc:59
 hkalplane.cc:60
 hkalplane.cc:61
 hkalplane.cc:62
 hkalplane.cc:63
 hkalplane.cc:64
 hkalplane.cc:65
 hkalplane.cc:66
 hkalplane.cc:67
 hkalplane.cc:68
 hkalplane.cc:69
 hkalplane.cc:70
 hkalplane.cc:71
 hkalplane.cc:72
 hkalplane.cc:73
 hkalplane.cc:74
 hkalplane.cc:75
 hkalplane.cc:76
 hkalplane.cc:77
 hkalplane.cc:78
 hkalplane.cc:79
 hkalplane.cc:80
 hkalplane.cc:81
 hkalplane.cc:82
 hkalplane.cc:83
 hkalplane.cc:84
 hkalplane.cc:85
 hkalplane.cc:86
 hkalplane.cc:87
 hkalplane.cc:88
 hkalplane.cc:89
 hkalplane.cc:90
 hkalplane.cc:91
 hkalplane.cc:92
 hkalplane.cc:93
 hkalplane.cc:94
 hkalplane.cc:95
 hkalplane.cc:96
 hkalplane.cc:97
 hkalplane.cc:98
 hkalplane.cc:99
 hkalplane.cc:100
 hkalplane.cc:101
 hkalplane.cc:102
 hkalplane.cc:103
 hkalplane.cc:104
 hkalplane.cc:105
 hkalplane.cc:106
 hkalplane.cc:107
 hkalplane.cc:108
 hkalplane.cc:109
 hkalplane.cc:110
 hkalplane.cc:111
 hkalplane.cc:112
 hkalplane.cc:113
 hkalplane.cc:114
 hkalplane.cc:115
 hkalplane.cc:116
 hkalplane.cc:117
 hkalplane.cc:118
 hkalplane.cc:119
 hkalplane.cc:120
 hkalplane.cc:121
 hkalplane.cc:122
 hkalplane.cc:123
 hkalplane.cc:124
 hkalplane.cc:125
 hkalplane.cc:126
 hkalplane.cc:127
 hkalplane.cc:128
 hkalplane.cc:129
 hkalplane.cc:130
 hkalplane.cc:131
 hkalplane.cc:132
 hkalplane.cc:133
 hkalplane.cc:134
 hkalplane.cc:135
 hkalplane.cc:136
 hkalplane.cc:137
 hkalplane.cc:138
 hkalplane.cc:139
 hkalplane.cc:140
 hkalplane.cc:141
 hkalplane.cc:142
 hkalplane.cc:143
 hkalplane.cc:144
 hkalplane.cc:145
 hkalplane.cc:146
 hkalplane.cc:147
 hkalplane.cc:148
 hkalplane.cc:149
 hkalplane.cc:150
 hkalplane.cc:151
 hkalplane.cc:152
 hkalplane.cc:153
 hkalplane.cc:154
 hkalplane.cc:155
 hkalplane.cc:156
 hkalplane.cc:157
 hkalplane.cc:158
 hkalplane.cc:159
 hkalplane.cc:160
 hkalplane.cc:161
 hkalplane.cc:162
 hkalplane.cc:163