// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: G4Ellipse.icc,v 1.8 2006/06/29 18:39:18 gunter Exp $ // GEANT4 tag $Name: geant4-09-03 $ // // -------------------------------------------------------------------- // GEANT 4 inline definitions file // // G4Ellipse.icc // // Implementation of inline methods of G4Ellipse // -------------------------------------------------------------------- inline void G4Ellipse::Init(const G4Axis2Placement3D& position0, G4double semiAxis10, G4double semiAxis20) { position= position0; semiAxis1= semiAxis10; semiAxis2= semiAxis20; ratioAxis2Axis1= semiAxis2/semiAxis1; SetBounds(0, 0); // needed only for 2D ellipses toUnitCircle = G4Scale3D(1/semiAxis1, 1/semiAxis2, 0) * position.GetToPlacementCoordinates(); forTangent= -semiAxis1*semiAxis1/(semiAxis2*semiAxis2); } inline G4double G4Ellipse::GetSemiAxis1() const { return semiAxis1; } inline G4double G4Ellipse::GetSemiAxis2() const { return semiAxis2; } ///////////////////////////////////////////////////////////////////////////// inline G4double G4Ellipse::GetPMax() const { return twopi; } inline G4Point3D G4Ellipse::GetPoint(G4double param) const { param-= GetPShift(); return G4Point3D( position.GetLocation() + semiAxis1*std::cos(param)*position.GetPX() + semiAxis2*std::sin(param)*position.GetPY() ); } inline G4double G4Ellipse::GetPPoint(const G4Point3D& pt) const { G4Point3D ptLocal= position.GetToPlacementCoordinates()*pt; G4double angle= std::atan2(ptLocal.y(), ptLocal.x()*ratioAxis2Axis1); G4double r= (angle<0)? angle+twopi: angle; return r+GetPShift(); } ///////////////////////////////////////////////////////////////////////////// #include "G4CurveRayIntersection.hh" /* inline void G4Ellipse::IntersectRay2D(const G4Ray& ray, G4CurveRayIntersection& is) { is.Init(*this, ray); // transform s.t. the ellipse becomes the unit circle // with the center at the origin // 2D operations would be faster G4Point3D s= toUnitCircle*ray.GetStart(); G4Vector3D d= toUnitCircle*ray.GetDir(); // solve (s+i*t)^2 = 1 for i (the distance) G4double sd= s*d; G4double dd= d.mag2(); // never 0 G4double ss= s.mag2(); G4double discr= sd*sd-dd*(ss-1); if (discr >= 0) { // 2 intersections (maybe 1, but this case is rare) G4double sqrtdiscr= std::sqrt(discr); // find the smallest positive i G4double i= -sd-sqrtdiscr; if (i 0) { // 2 intersections G4double sqrtdiscr= std::sqrt(discr); // if i is positive, we have an intersection i= -sd-sqrtdiscr; if (i > kCarTolerance) nbinter++; i= -sd+sqrtdiscr; if (i > kCarTolerance) nbinter++; } // if the ray is tangent on the circle if (discr == 0) nbinter = 1; return nbinter; }