source: trunk/source/geometry/solids/BREPS/include/G4Hyperbola.icc@ 1350

Last change on this file since 1350 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 5.4 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
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. *
10// * *
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. *
17// * *
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// ********************************************************************
25//
26//
27// $Id: G4Hyperbola.icc,v 1.9 2006/06/29 18:39:38 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30// --------------------------------------------------------------------
31// GEANT 4 inline definitions file
32//
33// G4Hyperbola.icc
34//
35// Implementation of inline methods of G4Hyperbola
36// --------------------------------------------------------------------
37
38inline
39void G4Hyperbola::Init(G4Axis2Placement3D position0,
40 G4double semiAxis0, G4double semiImagAxis0)
41{
42 position= position0;
43 semiAxis= semiAxis0;
44 semiImagAxis= semiImagAxis0;
45
46 ratioAxisImagAxis= semiAxis/semiImagAxis;
47
48 // needed only for 2D hyperbolas
49 toUnitHyperbola = G4Scale3D(1/semiAxis, 1/semiImagAxis, 0)
50 * position.GetToPlacementCoordinates();
51
52 forTangent= semiAxis*semiAxis/(semiImagAxis*semiImagAxis);
53}
54
55inline
56G4double G4Hyperbola::GetSemiAxis() const
57{
58 return semiAxis;
59}
60
61inline
62G4double G4Hyperbola::GetSemiImagAxis() const
63{
64 return semiImagAxis;
65}
66
67//////////////////////////////////////////////////////////////////////////////
68
69inline
70G4double G4Hyperbola::GetPMax() const
71{
72 return -1;
73}
74
75inline
76G4Point3D G4Hyperbola::GetPoint(G4double param) const
77{
78 return G4Point3D( position.GetLocation()
79 + semiAxis*std::cosh(param)*position.GetPX()
80 + semiImagAxis*std::sinh(param)*position.GetPY() );
81}
82
83inline
84G4double G4Hyperbola::GetPPoint(const G4Point3D& pt) const
85{
86 G4Point3D ptLocal= position.GetToPlacementCoordinates()*pt;
87 G4double xval= ptLocal.y()/ptLocal.x()*ratioAxisImagAxis;
88 return 0.5*std::log((1+xval)/(1-xval)); // atanh(xval)
89}
90
91/////////////////////////////////////////////////////////////////////////////
92
93/*
94#include "G4CurveRayIntersection.hh"
95
96inline
97void G4Hyperbola::IntersectRay2D(const G4Ray& ray,
98 G4CurveRayIntersection& is)
99{
100 is.Init(*this, ray);
101
102 // similar to G4Ellipse::IntersectRay2D
103
104 // 2D operations would be faster
105 G4Point3D s= toUnitHyperbola*ray.GetStart();
106 G4Vector3D d= toUnitHyperbola*ray.GetDir();
107
108 // solve (s+i*t)^2 = 1 for i (the distance)
109
110 G4double sd= s.x()*d.x()-s.y()*d.y();
111 G4double dd= d.x()*d.x()-d.y()*d.y(); // can be 0
112 G4double ss= s.x()*s.x()-s.y()*s.y();
113
114 if (std::abs(dd) < kCarTolerance*kCarTolerance) {
115
116 // coeff of i^2 == 0
117 G4double i= (1-ss)/(2*sd);
118 G4CurveRayIntersection isTmp(*this, ray);
119 isTmp.ResetDistance(i);
120 is.Update(isTmp);
121 return;
122
123 }
124
125 G4double discr= sd*sd-dd*(ss-1);
126 if (discr >= 0) {
127
128 // 2 intersections (maybe 1, but this case is rare)
129 G4double sqrtdiscr= std::sqrt(discr);
130 // find the smallest positive i
131 G4double i= -sd-sqrtdiscr;
132 if (i<kCarTolerance) {
133 i= -sd+sqrtdiscr;
134 if (i<kCarTolerance) {
135 return;
136 }
137 }
138 i/= dd;
139 G4CurveRayIntersection isTmp(*this, ray);
140 isTmp.ResetDistance(i);
141 is.Update(isTmp);
142
143 }
144}
145*/
146
147inline
148G4int G4Hyperbola::IntersectRay2D(const G4Ray& ray)
149{
150 // NOT VERIFIED
151
152 // similar to G4Ellipse::IntersectRay2D
153
154 // 2D operations would be faster
155 G4Point3D s= toUnitHyperbola*ray.GetStart();
156 G4Vector3D d= toUnitHyperbola*ray.GetDir();
157
158 // solve (s+i*t)^2 = 1 for i (the distance)
159
160 G4double sd= s.x()*d.x()-s.y()*d.y();
161 G4double dd= d.x()*d.x()-d.y()*d.y(); // can be 0
162 G4double ss= s.x()*s.x()-s.y()*s.y();
163
164 if (std::abs(dd) < kCarTolerance*kCarTolerance) {
165
166 // coeff of i^2 == 0
167 return 0;
168
169 }
170
171 G4int nbinter = 0;
172
173 G4double discr= sd*sd-dd*(ss-1);
174 if (discr >= 0)
175 {
176 // 2 intersections (maybe 1, but this case is rare)
177 G4double sqrtdiscr= std::sqrt(discr);
178 // find the smallest positive i
179 G4double i= -sd-sqrtdiscr;
180 if (i > kCarTolerance)
181 nbinter++;
182
183 i= -sd+sqrtdiscr;
184 if (i<kCarTolerance)
185 nbinter++;
186 }
187
188 return nbinter;
189}
Note: See TracBrowser for help on using the repository browser.