Example usage for org.apache.commons.math3.analysis.differentiation DerivativeStructure hypot

List of usage examples for org.apache.commons.math3.analysis.differentiation DerivativeStructure hypot

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.differentiation DerivativeStructure hypot.

Prototype

public static DerivativeStructure hypot(final DerivativeStructure x, final DerivativeStructure y)
        throws DimensionMismatchException 

Source Link

Document

Returns the hypotenuse of a triangle with sides x and y - sqrt(x2 +y2)
avoiding intermediate overflow or underflow.

Usage

From source file:org.orekit.bodies.OneAxisEllipsoid.java

/** Transform a Cartesian point to a surface-relative point.
 * @param point Cartesian point//from   w ww. j a  v a  2 s.co m
 * @param frame frame in which Cartesian point is expressed
 * @param date date of the computation (used for frames conversions)
 * @return point at the same location but as a surface-relative point,
 * using time as the single derivation parameter
 * @exception OrekitException if point cannot be converted to body frame
 */
public FieldGeodeticPoint<DerivativeStructure> transform(final PVCoordinates point, final Frame frame,
        final AbsoluteDate date) throws OrekitException {

    // transform point to body frame
    final Transform toBody = frame.getTransformTo(bodyFrame, date);
    final PVCoordinates pointInBodyFrame = toBody.transformPVCoordinates(point);
    final FieldVector3D<DerivativeStructure> p = pointInBodyFrame.toDerivativeStructureVector(2);
    final DerivativeStructure pr2 = p.getX().multiply(p.getX()).add(p.getY().multiply(p.getY()));
    final DerivativeStructure pr = pr2.sqrt();
    final DerivativeStructure pz = p.getZ();

    // project point on the ellipsoid surface
    final TimeStampedPVCoordinates groundPoint = projectToGround(
            new TimeStampedPVCoordinates(date, pointInBodyFrame), bodyFrame);
    final FieldVector3D<DerivativeStructure> gp = groundPoint.toDerivativeStructureVector(2);
    final DerivativeStructure gpr2 = gp.getX().multiply(gp.getX()).add(gp.getY().multiply(gp.getY()));
    final DerivativeStructure gpr = gpr2.sqrt();
    final DerivativeStructure gpz = gp.getZ();

    // relative position of test point with respect to its ellipse sub-point
    final DerivativeStructure dr = pr.subtract(gpr);
    final DerivativeStructure dz = pz.subtract(gpz);
    final double insideIfNegative = g2 * (pr2.getReal() - ae2) + pz.getReal() * pz.getReal();

    return new FieldGeodeticPoint<DerivativeStructure>(DerivativeStructure.atan2(gpz, gpr.multiply(g2)),
            DerivativeStructure.atan2(p.getY(), p.getX()),
            DerivativeStructure.hypot(dr, dz).copySign(insideIfNegative));
}