26 ClassImp(TGeoHalfSpace);
31 TGeoHalfSpace::TGeoHalfSpace()
33 SetShapeBit(TGeoShape::kGeoHalfSpace);
34 SetShapeBit(TGeoShape::kGeoInvalidShape);
35 memset(fP, 0, 3*
sizeof(Double_t));
36 memset(fN, 0, 3*
sizeof(Double_t));
42 TGeoHalfSpace::TGeoHalfSpace(
const char *name, Double_t *p, Double_t *n)
43 :TGeoBBox(name, 0,0,0)
45 SetShapeBit(TGeoShape::kGeoHalfSpace);
46 SetShapeBit(TGeoShape::kGeoInvalidShape);
48 memcpy(param, p, 3*
sizeof(Double_t));
49 memcpy(¶m[3], n, 3*
sizeof(Double_t));
56 TGeoHalfSpace::TGeoHalfSpace(Double_t *param)
59 SetShapeBit(TGeoShape::kGeoHalfSpace);
60 SetShapeBit(TGeoShape::kGeoInvalidShape);
67 TGeoHalfSpace::~TGeoHalfSpace()
74 void TGeoHalfSpace::ComputeNormal(
const Double_t * ,
const Double_t *dir, Double_t *norm)
76 memcpy(norm, fN, 3*
sizeof(Double_t));
77 if (norm[0]*dir[0]+norm[1]*dir[1]+norm[2]*dir[2]<0) {
87 Bool_t TGeoHalfSpace::Contains(
const Double_t *point)
const
90 r[0] = fP[0]-point[0];
91 r[1] = fP[1]-point[1];
92 r[2] = fP[2]-point[2];
93 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
94 if (rdotn < 0)
return kFALSE;
101 Int_t TGeoHalfSpace::DistancetoPrimitive(Int_t , Int_t )
109 Double_t TGeoHalfSpace::DistFromInside(
const Double_t *point,
const Double_t *dir, Int_t iact, Double_t step, Double_t *safe)
const
112 r[0] = fP[0]-point[0];
113 r[1] = fP[1]-point[1];
114 r[2] = fP[2]-point[2];
115 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
116 if (iact<3 && safe) {
118 if (iact==0)
return TGeoShape::Big();
119 if ((iact==1) && (*safe>step))
return TGeoShape::Big();
122 Double_t snxt = TGeoShape::Big();
123 Double_t ddotn = dir[0]*fN[0]+dir[1]*fN[1]+dir[2]*fN[2];
124 if (TMath::Abs(ddotn)<TGeoShape::Tolerance())
return snxt;
126 if (snxt<0)
return TGeoShape::Big();
133 Double_t TGeoHalfSpace::DistFromOutside(
const Double_t *point,
const Double_t *dir, Int_t iact, Double_t step, Double_t *safe)
const
136 r[0] = fP[0]-point[0];
137 r[1] = fP[1]-point[1];
138 r[2] = fP[2]-point[2];
139 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
140 if (iact<3 && safe) {
142 if (iact==0)
return TGeoShape::Big();
143 if ((iact==1) && (step<*safe))
return TGeoShape::Big();
146 Double_t snxt = TGeoShape::Big();
147 Double_t ddotn = dir[0]*fN[0]+dir[1]*fN[1]+dir[2]*fN[2];
148 if (TMath::Abs(ddotn)<TGeoShape::Tolerance())
return snxt;
150 if (snxt<0)
return TGeoShape::Big();
157 TGeoVolume *TGeoHalfSpace::Divide(TGeoVolume * ,
const char * , Int_t , Int_t ,
158 Double_t , Double_t )
160 Error(
"Divide",
"Half-spaces cannot be divided");
167 void TGeoHalfSpace::GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols)
const
177 void TGeoHalfSpace::InspectShape()
const
179 printf(
"*** Shape %s: TGeoHalfSpace ***\n", GetName());
180 printf(
" Point : %11.5f, %11.5f, %11.5f\n", fP[0], fP[1], fP[2]);
181 printf(
" Normal : %11.5f, %11.5f, %11.5f\n", fN[0], fN[1], fN[2]);
188 Double_t TGeoHalfSpace::Safety(
const Double_t *point, Bool_t )
const
191 r[0] = fP[0]-point[0];
192 r[1] = fP[1]-point[1];
193 r[2] = fP[2]-point[2];
194 Double_t rdotn = r[0]*fN[0]+r[1]*fN[1]+r[2]*fN[2];
195 return TMath::Abs(rdotn);
201 void TGeoHalfSpace::SavePrimitive(std::ostream &out, Option_t * )
203 if (TObject::TestBit(kGeoSavePrimitive))
return;
204 out <<
" // Shape: " << GetName() <<
" type: " << ClassName() << std::endl;
205 out <<
" point[0] = " << fP[0] <<
";" << std::endl;
206 out <<
" point[1] = " << fP[1] <<
";" << std::endl;
207 out <<
" point[2] = " << fP[2] <<
";" << std::endl;
208 out <<
" norm[0] = " << fN[0] <<
";" << std::endl;
209 out <<
" norm[1] = " << fN[1] <<
";" << std::endl;
210 out <<
" norm[2] = " << fN[2] <<
";" << std::endl;
211 out <<
" TGeoShape *" << GetPointerName() <<
" = new TGeoHalfSpace(\"" << GetName() <<
"\", point,norm);" << std::endl;
212 TObject::SetBit(TGeoShape::kGeoSavePrimitive);
218 void TGeoHalfSpace::SetDimensions(Double_t *param)
220 memcpy(fP, param, 3*
sizeof(Double_t));
221 memcpy(fN, ¶m[3], 3*
sizeof(Double_t));
222 Double_t nsq = TMath::Sqrt(fN[0]*fN[0]+fN[1]*fN[1]+fN[2]*fN[2]);
233 void TGeoHalfSpace::Contains_v(
const Double_t *points, Bool_t *inside, Int_t vecsize)
const
235 for (Int_t i=0; i<vecsize; i++) inside[i] = Contains(&points[3*i]);
243 void TGeoHalfSpace::ComputeNormal_v(
const Double_t *points,
const Double_t *dirs, Double_t *norms, Int_t vecsize)
245 for (Int_t i=0; i<vecsize; i++) ComputeNormal(&points[3*i], &dirs[3*i], &norms[3*i]);
251 void TGeoHalfSpace::DistFromInside_v(
const Double_t *points,
const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step)
const
253 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromInside(&points[3*i], &dirs[3*i], 3, step[i]);
259 void TGeoHalfSpace::DistFromOutside_v(
const Double_t *points,
const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step)
const
261 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromOutside(&points[3*i], &dirs[3*i], 3, step[i]);
269 void TGeoHalfSpace::Safety_v(
const Double_t *points,
const Bool_t *inside, Double_t *safe, Int_t vecsize)
const
271 for (Int_t i=0; i<vecsize; i++) safe[i] = Safety(&points[3*i], inside[i]);