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