00001
00013 #include "RectangularBox.h"
00014
00015 using namespace HepGeom;
00016
00017 RectangularBox::RectangularBox(double xUp, double xLow,
00018 double yUp, double yLow,
00019 double zUp, double zLow)
00020 {
00021 m_xUp = xUp;
00022 m_xLow = xLow;
00023 m_yUp = yUp;
00024 m_yLow = yLow;
00025 m_zUp = zUp;
00026 m_zLow = zLow;
00027 }
00028
00029
00030 RectangularBox::~RectangularBox()
00031 {}
00032
00033 bool RectangularBox::intersect(const Point3D<double> & linePoint, const Normal3D<double> & lineSlope,
00034 Point3D<double> & intersectA, Point3D<double> & intersectB)
00035 {
00036 Point3D<double> aPoint=linePoint;
00037 Normal3D<double> aSlope=lineSlope;
00038
00039 bool foundA;
00040 bool foundB;
00041
00042 foundA=foundB=false;
00043
00044 double x,y,z;
00045
00047
00048 if(foundA && foundB) return true;
00049
00050 if( aSlope.z()!=0 ) {
00051 x=aSlope.x()/aSlope.z()*(m_zUp-aPoint.z()) + aPoint.x();
00052 y=aSlope.y()/aSlope.z()*(m_zUp-aPoint.z()) + aPoint.y();
00053
00054 if(x>=m_xLow && x<=m_xUp &&
00055 y>=m_yLow && y<=m_yUp ) {
00056 if(!foundA) {
00057 foundA = true;
00058 intersectA.setX(x);
00059 intersectA.setY(y);
00060 intersectA.setZ(m_zUp);
00061 } else {
00062 if (!foundB) {
00063 foundB = true;
00064 intersectB.setX(x);
00065 intersectB.setY(y);
00066 intersectB.setZ(m_zUp);
00067 }
00068 }
00069 }
00070 }
00071
00072
00073 if(foundA && foundB) return true;
00074
00075 if( aSlope.z()!=0 ) {
00076 x=aSlope.x()/aSlope.z()*(m_zLow-aPoint.z()) + aPoint.x();
00077 y=aSlope.y()/aSlope.z()*(m_zLow-aPoint.z()) + aPoint.y();
00078
00079 if(x>=m_xLow && x<=m_xUp &&
00080 y>=m_yLow && y<=m_yUp ) {
00081 if(!foundA) {
00082 foundA = true;
00083 intersectA.setX(x);
00084 intersectA.setY(y);
00085 intersectA.setZ(m_zLow);
00086 } else {
00087 if (!foundB) {
00088 foundB = true;
00089 intersectB.setX(x);
00090 intersectB.setY(y);
00091 intersectB.setZ(m_zLow);
00092 }
00093 }
00094 }
00095 }
00096
00098
00099 if(foundA && foundB) return true;
00100
00101 if( aSlope.x()!=0 ) {
00102 z=aSlope.z()/aSlope.x()*(m_xUp-aPoint.x()) + aPoint.z();
00103 y=aSlope.y()/aSlope.x()*(m_xUp-aPoint.x()) + aPoint.y();
00104
00105 if(z>=m_zLow && z<=m_zUp &&
00106 y>=m_yLow && y<=m_yUp ) {
00107 if(!foundA) {
00108 foundA = true;
00109 intersectA.setZ(z);
00110 intersectA.setY(y);
00111 intersectA.setX(m_xUp);
00112 } else {
00113 if (!foundB) {
00114 foundB = true;
00115 intersectB.setZ(z);
00116 intersectB.setY(y);
00117 intersectB.setX(m_xUp);
00118 }
00119 }
00120 }
00121 }
00122
00123
00124 if(foundA && foundB) return true;
00125
00126 if( aSlope.x()!=0 ) {
00127 z=aSlope.z()/aSlope.x()*(m_xLow-aPoint.x()) + aPoint.z();
00128 y=aSlope.y()/aSlope.x()*(m_xLow-aPoint.x()) + aPoint.y();
00129
00130 if(z>=m_zLow && z<=m_zUp &&
00131 y>=m_yLow && y<=m_yUp ) {
00132 if(!foundA) {
00133 foundA = true;
00134 intersectA.setZ(z);
00135 intersectA.setY(y);
00136 intersectA.setX(m_xLow);
00137 } else {
00138 if (!foundB) {
00139 foundB = true;
00140 intersectB.setZ(z);
00141 intersectB.setY(y);
00142 intersectB.setX(m_xLow);
00143 }
00144 }
00145 }
00146 }
00147
00148
00150
00151 if(foundA && foundB) return true;
00152
00153 if( aSlope.y()!=0 ) {
00154 z=aSlope.z()/aSlope.y()*(m_yUp-aPoint.y()) + aPoint.z();
00155 x=aSlope.x()/aSlope.y()*(m_yUp-aPoint.y()) + aPoint.x();
00156
00157 if(z>=m_zLow && z<=m_zUp &&
00158 x>=m_xLow && x<=m_xUp ) {
00159 if(!foundA) {
00160 foundA = true;
00161 intersectA.setZ(z);
00162 intersectA.setX(x);
00163 intersectA.setY(m_yUp);
00164 } else {
00165 if (!foundB) {
00166 foundB = true;
00167 intersectB.setZ(z);
00168 intersectB.setX(x);
00169 intersectB.setY(m_yUp);
00170 }
00171 }
00172 }
00173 }
00174
00175
00176 if(foundA && foundB) return true;
00177
00178 if( aSlope.y()!=0 ) {
00179 z=aSlope.z()/aSlope.y()*(m_yLow-aPoint.y()) + aPoint.z();
00180 x=aSlope.x()/aSlope.y()*(m_yLow-aPoint.y()) + aPoint.x();
00181
00182 if(z>=m_zLow && z<=m_zUp &&
00183 x>=m_xLow && x<=m_xUp ) {
00184 if(!foundA) {
00185 foundA = true;
00186 intersectA.setZ(z);
00187 intersectA.setX(x);
00188 intersectA.setY(m_yLow);
00189 } else {
00190 if (!foundB) {
00191 foundB = true;
00192 intersectB.setZ(z);
00193 intersectB.setX(x);
00194 intersectB.setY(m_yLow);
00195 }
00196 }
00197 }
00198 }
00199
00200 return foundA && foundB;
00201 }
00202
00203
00204 std::ostream & operator<<(std::ostream & os, const RectangularBox & p)
00205 {
00206 os<<"xUp="<<p.xUp()<<" "<<"xLow="<<p.xLow()<<" "
00207 <<"yUp="<<p.yUp()<<" "<<"yLow="<<p.yLow()<<" "
00208 <<"zUp="<<p.zUp()<<" "<<"zLow="<<p.zLow();
00209
00210 return os;
00211 }
00212