source: trunk/source/geometry/solids/BREPS/include/G4Ellipse.icc@ 1116

Last change on this file since 1116 was 1058, checked in by garnier, 17 years ago

file release beta

File size: 5.1 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: G4Ellipse.icc,v 1.8 2006/06/29 18:39:18 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30// --------------------------------------------------------------------
31// GEANT 4 inline definitions file
32//
33// G4Ellipse.icc
34//
35// Implementation of inline methods of G4Ellipse
36// --------------------------------------------------------------------
37
38inline
39void G4Ellipse::Init(const G4Axis2Placement3D& position0,
40 G4double semiAxis10, G4double semiAxis20)
41{
42 position= position0;
43 semiAxis1= semiAxis10;
44 semiAxis2= semiAxis20;
45
46 ratioAxis2Axis1= semiAxis2/semiAxis1;
47
48 SetBounds(0, 0);
49
50 // needed only for 2D ellipses
51 toUnitCircle = G4Scale3D(1/semiAxis1, 1/semiAxis2, 0)
52 * position.GetToPlacementCoordinates();
53
54 forTangent= -semiAxis1*semiAxis1/(semiAxis2*semiAxis2);
55}
56
57inline
58G4double G4Ellipse::GetSemiAxis1() const
59{
60 return semiAxis1;
61}
62
63inline
64G4double G4Ellipse::GetSemiAxis2() const
65{
66 return semiAxis2;
67}
68
69/////////////////////////////////////////////////////////////////////////////
70
71inline
72G4double G4Ellipse::GetPMax() const
73{
74 return twopi;
75}
76
77inline
78G4Point3D G4Ellipse::GetPoint(G4double param) const
79{
80 param-= GetPShift();
81 return G4Point3D( position.GetLocation()
82 + semiAxis1*std::cos(param)*position.GetPX()
83 + semiAxis2*std::sin(param)*position.GetPY() );
84}
85
86inline
87G4double G4Ellipse::GetPPoint(const G4Point3D& pt) const
88{
89 G4Point3D ptLocal= position.GetToPlacementCoordinates()*pt;
90 G4double angle= std::atan2(ptLocal.y(), ptLocal.x()*ratioAxis2Axis1);
91 G4double r= (angle<0)? angle+twopi: angle;
92 return r+GetPShift();
93}
94
95/////////////////////////////////////////////////////////////////////////////
96
97#include "G4CurveRayIntersection.hh"
98
99/*
100inline
101void G4Ellipse::IntersectRay2D(const G4Ray& ray,
102 G4CurveRayIntersection& is)
103{
104 is.Init(*this, ray);
105
106 // transform s.t. the ellipse becomes the unit circle
107 // with the center at the origin
108
109 // 2D operations would be faster
110 G4Point3D s= toUnitCircle*ray.GetStart();
111 G4Vector3D d= toUnitCircle*ray.GetDir();
112
113 // solve (s+i*t)^2 = 1 for i (the distance)
114
115 G4double sd= s*d;
116 G4double dd= d.mag2(); // never 0
117 G4double ss= s.mag2();
118
119 G4double discr= sd*sd-dd*(ss-1);
120 if (discr >= 0) {
121
122 // 2 intersections (maybe 1, but this case is rare)
123 G4double sqrtdiscr= std::sqrt(discr);
124 // find the smallest positive i
125 G4double i= -sd-sqrtdiscr;
126 if (i<kCarTolerance) {
127 i= -sd+sqrtdiscr;
128 if (i<kCarTolerance) {
129 return;
130 }
131 }
132 i/= dd;
133 G4CurveRayIntersection isTmp(*this, ray);
134 isTmp.ResetDistance(i);
135 is.Update(isTmp);
136
137 }
138}
139*/
140
141inline
142G4int G4Ellipse::IntersectRay2D(const G4Ray& ray)
143{
144 // transform s.t. the ellipse becomes the unit circle
145 // with the center at the origin
146
147 // 2D operations would be faster
148 G4Point3D s= toUnitCircle*ray.GetStart();
149 G4Vector3D d= toUnitCircle*ray.GetDir();
150
151 // solve (s+i*t)^2 = 1 for i (the distance)
152 G4double sd= s*d;
153 G4double dd= d.mag2(); // never 0
154 G4double ss= s.mag2();
155
156 G4double discr= sd*sd-dd*(ss-1);
157 G4int nbinter = 0;
158 G4double i;
159
160 if (discr > 0)
161 {
162 // 2 intersections
163 G4double sqrtdiscr= std::sqrt(discr);
164
165 // if i is positive, we have an intersection
166 i= -sd-sqrtdiscr;
167 if (i > kCarTolerance)
168 nbinter++;
169
170 i= -sd+sqrtdiscr;
171 if (i > kCarTolerance)
172 nbinter++;
173 }
174
175 // if the ray is tangent on the circle
176 if (discr == 0)
177 nbinter = 1;
178
179 return nbinter;
180}
Note: See TracBrowser for help on using the repository browser.