source: trunk/source/geometry/solids/BREPS/src/G4Ellipse.cc@ 1311

Last change on this file since 1311 was 1228, checked in by garnier, 16 years ago

update geant4.9.3 tag

File size: 6.2 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.cc,v 1.12 2007/05/18 07:33:31 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30// ----------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4Ellipse.cc
34//
35// ----------------------------------------------------------------------
36
37#include "G4Ellipse.hh"
38
39#include "G4GeometryTolerance.hh"
40
41G4Ellipse::G4Ellipse()
42{
43}
44
45G4Ellipse::~G4Ellipse()
46{
47}
48
49G4Ellipse::G4Ellipse(const G4Ellipse& right)
50 : G4Conic(), semiAxis1(right.semiAxis1), semiAxis2(right.semiAxis2),
51 ratioAxis2Axis1(right.ratioAxis2Axis1), toUnitCircle(right.toUnitCircle),
52 forTangent(right.forTangent)
53{
54 pShift = right.pShift;
55 position = right.position;
56 bBox = right.bBox;
57 start = right.start;
58 end = right.end;
59 pStart = right.pStart;
60 pEnd = right.pEnd;
61 pRange = right.pRange;
62 bounded = right.bounded;
63 sameSense = right.sameSense;
64}
65
66G4Ellipse& G4Ellipse::operator=(const G4Ellipse& right)
67{
68 if (&right == this) return *this;
69
70 semiAxis1 = right.semiAxis1;
71 semiAxis2 = right.semiAxis2;
72 ratioAxis2Axis1 = right.ratioAxis2Axis1;
73 toUnitCircle = right.toUnitCircle;
74 forTangent = right.forTangent;
75 pShift = right.pShift;
76 position = right.position;
77 bBox = right.bBox;
78 start = right.start;
79 end = right.end;
80 pStart = right.pStart;
81 pEnd = right.pEnd;
82 pRange = right.pRange;
83 bounded = right.bounded;
84 sameSense = right.sameSense;
85
86 return *this;
87}
88
89G4Curve* G4Ellipse::Project(const G4Transform3D& tr)
90{
91 G4Point3D newLocation = tr*position.GetLocation();
92 newLocation.setZ(0);
93 G4double axisZ = ( tr*position.GetPZ() ).unit().z();
94
95 if (std::abs(axisZ)<G4GeometryTolerance::GetInstance()->GetAngularTolerance())
96 { return 0; }
97
98 G4Vector3D newAxis(0, 0, axisZ>0? +1: -1);
99
100 // get the parameter of an endpoint of an axis
101 // (this is a point the distance of which from the center is extreme)
102 G4Vector3D xPrime= tr*position.GetPX();
103 xPrime.setZ(0);
104 G4Vector3D yPrime= tr*position.GetPY();
105 yPrime.setZ(0);
106
107 G4Vector3D a = G4Vector3D( semiAxis1*xPrime );
108 G4Vector3D b = G4Vector3D( semiAxis2*yPrime );
109
110 G4double u;
111 G4double abmag = a.mag2()-b.mag2();
112 G4double prod = 2*a*b;
113
114 if ((abmag > FLT_MAX) && (prod < -FLT_MAX))
115 u = -pi/8;
116 else if ((abmag < -FLT_MAX) && (prod > FLT_MAX))
117 u = 3*pi/8;
118 else if ((abmag < -FLT_MAX) && (prod < -FLT_MAX))
119 u = -3*pi/8;
120 else if ((std::abs(abmag) < perMillion) && (std::abs(prod) < perMillion))
121 u = 0.;
122 else
123 u = std::atan2(prod,abmag) / 2;
124
125 // get the coordinate axis directions and the semiaxis lengths
126 G4Vector3D sAxis1 = G4Vector3D( a*std::cos(u)+b*std::sin(u) );
127 G4Vector3D sAxis2 = G4Vector3D( a*std::cos(u+pi/2)+b*std::sin(u+pi/2) );
128 G4double newSemiAxis1 = sAxis1.mag();
129 G4double newSemiAxis2 = sAxis2.mag();
130 G4Vector3D newRefDirection = sAxis1;
131
132 // create the new ellipse
133 G4Axis2Placement3D newPosition;
134 newPosition.Init(newRefDirection, newAxis, newLocation);
135 G4Ellipse* r= new G4Ellipse;
136 r->Init(newPosition, newSemiAxis1, newSemiAxis2);
137
138 // introduce the shift in the parametrization
139 // maybe the Sign must be changed?
140 r->SetPShift(u);
141
142 // set the bounds when necessary
143 if (IsBounded())
144 r->SetBounds(GetPStart(), GetPEnd());
145
146 // L. Broglia
147 // copy sense of the curve
148 r->SetSameSense(GetSameSense());
149
150 return r;
151}
152
153void G4Ellipse::InitBounded()
154{
155 // original implementation
156 // const G4Point3D& center = position.GetLocation();
157 // G4double maxEntent = std::max(semiAxis1, semiAxis2);
158 // G4Vector3D halfExtent(maxEntent, maxEntent, maxEntent);
159 // bBox.Init(center+halfExtent, center-halfExtent);
160
161 // the bbox must include the start and endpoints as well as the
162 // extreme points if they lie on the curve
163 bBox.Init(GetStart(), GetEnd());
164
165 // the parameter values
166 // belonging to the points with an extreme x, y and z coordinate
167 for (G4int i=0; i<3; i++)
168 {
169 G4double u= std::atan2(position.GetPY()(i)*semiAxis2,
170 position.GetPX()(i)*semiAxis1);
171 if (IsPOn(u))
172 bBox.Extend(GetPoint(u));
173
174 if (IsPOn(u+pi))
175 bBox.Extend(GetPoint(u+pi));
176 }
177}
178
179
180G4bool G4Ellipse::Tangent(G4CurvePoint& cp, G4Vector3D& v)
181{
182 // The tangent is computed from the 3D point representation
183 // for all conics. An alternaive implementation (based on
184 // the parametric point) might be worthwhile adding
185 // for efficiency.
186
187 const G4Axis2Placement3D& pos = *(GetPosition());
188 G4Point3D p= pos.GetToPlacementCoordinates() * cp.GetPoint();
189
190 v=forTangent*p.y()*pos.GetPX() + p.x()*pos.GetPY();
191 if(GetSameSense())
192 v = -v;
193
194 return true;
195}
196
Note: See TracBrowser for help on using the repository browser.