2// ********************************************************************
3// * License and Disclaimer *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
26// G4VTwistSurface class inline methods
28// 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp), created.
29// 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
30// from original version in Jupiter-2.5.02 application.
31// --------------------------------------------------------------------
33//=====================================================================
34//* DistanceToPlaneWithV ----------------------------------------------
37G4double G4VTwistSurface::DistanceToPlaneWithV(const G4ThreeVector& p,
38 const G4ThreeVector& v,
39 const G4ThreeVector& x0,
40 const G4ThreeVector& n0,
44 G4double t = kInfinity;
45 if (q) { t = (n0 * (x0 - p)) / q; }
50//=====================================================================
51//* DistanceToPlane ---------------------------------------------------
54G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p,
55 const G4ThreeVector& x0,
56 const G4ThreeVector& n0,
60 // Calculate distance to plane in local coordinate,
61 // then return distance and global intersection points.
63 // p - location of flying particle
64 // x0 - reference point of surface
65 // xx - a foot of perpendicular line from p to the plane
66 // t - distance from xx to p
67 // n - a unit normal of this plane from plane to p.
76 // t = n * (p - x0) / std::fabs(n)
79 G4ThreeVector n = n0.unit();
85//=====================================================================
86//* DistanceToPlane ---------------------------------------------------
89G4double G4VTwistSurface::DistanceToPlane(const G4ThreeVector& p,
90 const G4ThreeVector& x0,
91 const G4ThreeVector& t1,
92 const G4ThreeVector& t2,
97 // Calculate distance to plane in local coordinate,
98 // then return distance and global intersection points.
99 // t1 - 1st. vector lying on the plane
100 // t2 - 2nd. vector lying on the plane
102 n = (t1.cross(t2)).unit();
103 return DistanceToPlane(p, x0, n, xx);
106//=====================================================================
107//* DistanceToLine ----------------------------------------------------
110G4double G4VTwistSurface::DistanceToLine(const G4ThreeVector& p,
111 const G4ThreeVector& x0,
112 const G4ThreeVector& d,
116 // Calculate distance to line,
117 // then return distance and global intersection points.
119 // p - location of flying particle
120 // x0 - reference point of line
121 // d - direction vector of line
122 // xx - a foot of perpendicular line from p to the plane
123 // t - distance from xx to p
127 // distance^2 = |(xx - p)|^2
131 // (d/dt)distance^2 = (d/dt)|((x0 + t*d) - p)|^2
132 // = 2*t*|d|^2 + 2*d*(x0 - p)
133 // = 0 // smallest distance
135 // t = - d*(x0 - p) / |d|^2
139 G4ThreeVector dir = d.unit();
140 t = - dir * (x0 - p); // |dir|^2 = 1.
143 G4ThreeVector dist = xx - p;
147//=====================================================================
148//* IsAxis0 -----------------------------------------------------------
151G4bool G4VTwistSurface::IsAxis0(G4int areacode) const
153 if (areacode & sAxis0) return true;
157//=====================================================================
158//* IsAxis1 -----------------------------------------------------------
161G4bool G4VTwistSurface::IsAxis1(G4int areacode) const
163 if (areacode & sAxis1) return true;
167//=====================================================================
168//* IsOutside ---------------------------------------------------------
171G4bool G4VTwistSurface::IsOutside(G4int areacode) const
173 if (areacode & sInside) return false;
177//=====================================================================
178//* IsInside ----------------------------------------------------------
181G4bool G4VTwistSurface::IsInside(G4int areacode, G4bool testbitmode) const
183 if (areacode & sInside) {
187 if (!((areacode & sBoundary) || (areacode & sCorner))) return true;
193//=====================================================================
194//* IsBoundary --------------------------------------------------------
197G4bool G4VTwistSurface::IsBoundary(G4int areacode, G4bool testbitmode) const
199 if ((areacode & sBoundary) == sBoundary) {
203 if ((areacode & sInside) == sInside) return true;
209//=====================================================================
210//* IsCorner ----------------------------------------------------------
213G4bool G4VTwistSurface::IsCorner(G4int areacode, G4bool testbitmode) const
215 if ((areacode & sCorner) == sCorner) {
219 if ((areacode & sInside) == sInside) return true;
225//=====================================================================
226//* GetAxisType -------------------------------------------------------
229G4int G4VTwistSurface::GetAxisType(G4int areacode, G4int whichaxis) const
231 G4int axiscode = areacode & sAxisMask & whichaxis;
233 if (axiscode == (sAxisX & sAxis0) ||
234 axiscode == (sAxisX & sAxis1)) {
236 } else if (axiscode == (sAxisY & sAxis0) ||
237 axiscode == (sAxisY & sAxis1)) {
239 } else if (axiscode == (sAxisZ & sAxis0) ||
240 axiscode == (sAxisZ & sAxis1)) {
242 } else if (axiscode == (sAxisRho & sAxis0) ||
243 axiscode == (sAxisRho & sAxis1)) {
245 } else if (axiscode == (sAxisPhi & sAxis0) ||
246 axiscode == (sAxisPhi & sAxis1)) {
249 std::ostringstream message;
250 message << "Configuration not supported." << G4endl
251 << " areacode = " << areacode;
252 G4Exception("G4VTwistSurface::GetAxisType()","GeomSolids0001",
253 FatalException, message);
258//=====================================================================
259//* ComputeGlobalPoint ------------------------------------------------
262G4ThreeVector G4VTwistSurface::ComputeGlobalPoint(const G4ThreeVector& lp) const
264 return fRot * G4ThreeVector(lp) + fTrans;
267//=====================================================================
268//* ComputeGlobalPoint ------------------------------------------------
271G4ThreeVector G4VTwistSurface::ComputeLocalPoint(const G4ThreeVector& gp) const
273 return fRot.inverse() * ( G4ThreeVector(gp) - fTrans ) ;
276//=====================================================================
277//* ComputeGlobalDirection --------------------------------------------
280G4VTwistSurface::ComputeGlobalDirection(const G4ThreeVector& lp) const
282 return fRot * G4ThreeVector(lp);
285//=====================================================================
286//* ComputeLocalDirection ---------------------------------------------
289G4VTwistSurface::ComputeLocalDirection(const G4ThreeVector& gp) const
291 return fRot.inverse() * G4ThreeVector(gp);
294//=====================================================================
295//* SetNeighbours -----------------------------------------------------
298G4VTwistSurface::SetNeighbours(G4VTwistSurface* ax0min, G4VTwistSurface* ax1min,
299 G4VTwistSurface* ax0max, G4VTwistSurface* ax1max)
301 fNeighbours[0] = ax0min;
302 fNeighbours[1] = ax1min;
303 fNeighbours[2] = ax0max;
304 fNeighbours[3] = ax1max;
307//=====================================================================
308//* GetNeighbours -----------------------------------------------------
311G4VTwistSurface::GetNeighbours(G4int areacode, G4VTwistSurface** surfaces)
314 G4int sAxis0Min = sAxis0 & sAxisMin ;
315 G4int sAxis1Min = sAxis1 & sAxisMin ;
316 G4int sAxis0Max = sAxis0 & sAxisMax ;
317 G4int sAxis1Max = sAxis1 & sAxisMax ;
321 if ( (areacode & sAxis0Min ) == sAxis0Min )
323 surfaces[i] = fNeighbours[0] ;
327 if ( ( areacode & sAxis1Min ) == sAxis1Min )
329 surfaces[i] = fNeighbours[1] ;
331 if ( i == 2 ) return i ;
334 if ( ( areacode & sAxis0Max ) == sAxis0Max )
336 surfaces[i] = fNeighbours[2] ;
338 if ( i == 2 ) return i ;
341 if ( ( areacode & sAxis1Max ) == sAxis1Max )
343 surfaces[i] = fNeighbours[3] ;
345 if ( i == 2 ) return i ;
351//=====================================================================
352//* GetCorner ---------------------------------------------------------
355G4ThreeVector G4VTwistSurface::GetCorner(G4int areacode) const
357 if (!(areacode & sCorner))
359 std::ostringstream message;
360 message << "Area code must represent corner." << G4endl
361 << " areacode = " << areacode;
362 G4Exception("G4VTwistSurface::GetCorner()","GeomSolids0002",
363 FatalException, message);
366 if ((areacode & sC0Min1Min) == sC0Min1Min) {
368 } else if ((areacode & sC0Max1Min) == sC0Max1Min) {
370 } else if ((areacode & sC0Max1Max) == sC0Max1Max) {
372 } else if ((areacode & sC0Min1Max) == sC0Min1Max) {
375 std::ostringstream message;
376 message << "Configuration not supported." << G4endl
377 << " areacode = " << areacode;
378 G4Exception("G4VTwistSurface::GetCorner()", "GeomSolids0001",
379 FatalException, message);