List of usage examples for org.apache.commons.math3.analysis.solvers BracketingNthOrderBrentSolver BracketingNthOrderBrentSolver
public BracketingNthOrderBrentSolver()
From source file:org.orekit.models.earth.Geoid.java
/** * {@inheritDoc}// w w w .j a v a2s . c o m * * <p> The intersection point is computed using a line search along the * specified line. This is accurate when the geoid is slowly varying. */ @Override public GeodeticPoint getIntersectionPoint(final Line lineInFrame, final Vector3D closeInFrame, final Frame frame, final AbsoluteDate date) throws OrekitException { /* * It is assumed that the geoid is slowly varying over it's entire * surface. Therefore there will one local intersection. */ // transform to body frame final Frame bodyFrame = this.getBodyFrame(); final Transform frameToBody = frame.getTransformTo(bodyFrame, date); final Vector3D close = frameToBody.transformPosition(closeInFrame); final Line lineInBodyFrame = frameToBody.transformLine(lineInFrame); // set the line's direction so the solved for value is always positive final Line line; if (lineInBodyFrame.getAbscissa(close) < 0) { line = lineInBodyFrame.revert(); } else { line = lineInBodyFrame; } final ReferenceEllipsoid ellipsoid = this.getEllipsoid(); // calculate end points // distance from line to center of earth, squared final double d2 = line.pointAt(0.0).getNormSq(); // the minimum abscissa, squared final double minAbscissa2 = FastMath.pow(ellipsoid.getPolarRadius() + MIN_UNDULATION, 2) - d2; // smaller end point of the interval = 0.0 or intersection with // min_undulation sphere final double lowPoint = FastMath.sqrt(FastMath.max(minAbscissa2, 0.0)); // the maximum abscissa, squared final double maxAbscissa2 = FastMath.pow(ellipsoid.getEquatorialRadius() + MAX_UNDULATION, 2) - d2; // larger end point of the interval final double highPoint = FastMath.sqrt(maxAbscissa2); // line search function final UnivariateFunction heightFunction = new UnivariateFunction() { @Override public double value(final double x) { try { final GeodeticPoint geodetic = transform(line.pointAt(x), bodyFrame, date); return geodetic.getAltitude(); } catch (OrekitException e) { // due to frame transform -> re-throw throw new RuntimeException(e); } } }; // compute answer if (maxAbscissa2 < 0) { // ray does not pierce bounding sphere -> no possible intersection return null; } // solve line search problem to find the intersection final UnivariateSolver solver = new BracketingNthOrderBrentSolver(); try { final double abscissa = solver.solve(MAX_EVALUATIONS, heightFunction, lowPoint, highPoint); // return intersection point return this.transform(line.pointAt(abscissa), bodyFrame, date); } catch (TooManyEvaluationsException e) { // no intersection return null; } catch (MathIllegalArgumentException e) { // no intersection return null; } }