Example usage for org.apache.commons.math3.util MathArrays linearCombination

List of usage examples for org.apache.commons.math3.util MathArrays linearCombination

Introduction

In this page you can find the example usage for org.apache.commons.math3.util MathArrays linearCombination.

Prototype

public static double linearCombination(final double a1, final double b1, final double a2, final double b2) 

Source Link

Document

Compute a linear combination accurately.

Usage

From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java

@Override
public void linearCombination(final double a1, final double[] c1, final double a2, final double[] c2,
        final double[] result) {
    for (int i = 0; i < sizes[parameters][order]; ++i) {
        result[i] = MathArrays.linearCombination(a1, c1[i], a2, c2[i]);
    }// w  ww . j ava2s. c  o  m
}

From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java

@Override
@Optimizable// w  ww .j av  a2 s.com
@StrictLoops
public void linearCombination(final double a1, final double[] c1, final double a2, final double[] c2,
        final double[] result) {
    for (int i = 0; i < sizes[parameters][order]; ++i) {
        result[i] = MathArrays.linearCombination(a1, c1[i], a2, c2[i]);
    }
}

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

/** Find the closest ellipse point.
 * @param p point in the ellipse plane to project on the ellipse itself
 * @return closest point belonging to 2D meridian ellipse
 *//*from   w  w  w.j  ava2  s .  c  om*/
public Vector2D projectToEllipse(final Vector2D p) {

    final double x = FastMath.abs(p.getX());
    final double y = p.getY();

    if (x <= ANGULAR_THRESHOLD * FastMath.abs(y)) {
        // the point is almost on the minor axis, approximate the ellipse with
        // the osculating circle whose center is at evolute cusp along minor axis
        final double osculatingRadius = a2 / b;
        final double evoluteCuspZ = FastMath.copySign(a * e2 / g, -y);
        final double deltaZ = y - evoluteCuspZ;
        final double ratio = osculatingRadius / FastMath.hypot(deltaZ, x);
        return new Vector2D(FastMath.copySign(ratio * x, p.getX()), evoluteCuspZ + ratio * deltaZ);
    }

    if (FastMath.abs(y) <= ANGULAR_THRESHOLD * x) {
        // the point is almost on the major axis

        final double osculatingRadius = b2 / a;
        final double evoluteCuspR = a * e2;
        final double deltaR = x - evoluteCuspR;
        if (deltaR >= 0) {
            // the point is outside of the ellipse evolute, approximate the ellipse
            // with the osculating circle whose center is at evolute cusp along major axis
            final double ratio = osculatingRadius / FastMath.hypot(y, deltaR);
            return new Vector2D(FastMath.copySign(evoluteCuspR + ratio * deltaR, p.getX()), ratio * y);
        }

        // the point is on the part of the major axis within ellipse evolute
        // we can compute the closest ellipse point analytically
        final double rEllipse = x / e2;
        return new Vector2D(FastMath.copySign(rEllipse, p.getX()),
                FastMath.copySign(g * FastMath.sqrt(a2 - rEllipse * rEllipse), y));

    } else {
        final double k = FastMath.hypot(x / a, y / b);
        double projectedX = x / k;
        double projectedY = y / k;
        double deltaX = Double.POSITIVE_INFINITY;
        double deltaY = Double.POSITIVE_INFINITY;
        int count = 0;
        final double threshold = ANGULAR_THRESHOLD * ANGULAR_THRESHOLD * a2;
        while ((deltaX * deltaX + deltaY * deltaY) > threshold && count++ < 100) { // this loop usually converges in 3 iterations
            final double omegaX = evoluteFactorX * projectedX * projectedX * projectedX;
            final double omegaY = evoluteFactorY * projectedY * projectedY * projectedY;
            final double dx = x - omegaX;
            final double dy = y - omegaY;
            final double alpha = b2 * dx * dx + a2 * dy * dy;
            final double beta = b2 * omegaX * dx + a2 * omegaY * dy;
            final double gamma = b2 * omegaX * omegaX + a2 * omegaY * omegaY - a2 * b2;
            final double deltaPrime = MathArrays.linearCombination(beta, beta, -alpha, gamma);
            final double ratio = (beta <= 0) ? (FastMath.sqrt(deltaPrime) - beta) / alpha
                    : -gamma / (FastMath.sqrt(deltaPrime) + beta);
            final double previousX = projectedX;
            final double previousY = projectedY;
            projectedX = omegaX + ratio * dx;
            projectedY = omegaY + ratio * dy;
            deltaX = projectedX - previousX;
            deltaY = projectedY - previousY;
        }
        return new Vector2D(FastMath.copySign(projectedX, p.getX()), projectedY);
    }
}

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

/** {@inheritDoc} */
public TimeStampedPVCoordinates projectToGround(final TimeStampedPVCoordinates pv, final Frame frame)
        throws OrekitException {

    // transform point to body frame
    final Transform toBody = frame.getTransformTo(bodyFrame, pv.getDate());
    final TimeStampedPVCoordinates pvInBodyFrame = toBody.transformPVCoordinates(pv);
    final Vector3D p = pvInBodyFrame.getPosition();
    final double r = FastMath.hypot(p.getX(), p.getY());

    // set up the 2D ellipse corresponding to first principal curvature along meridian
    final Vector3D meridian = new Vector3D(p.getX() / r, p.getY() / r, 0);
    final Ellipse firstPrincipalCurvature = new Ellipse(Vector3D.ZERO, meridian, Vector3D.PLUS_K, getA(),
            getC(), bodyFrame);//from   w ww  .  j  a va2 s .  c  o  m

    // project coordinates in the meridian plane
    final TimeStampedPVCoordinates gpFirst = firstPrincipalCurvature.projectToEllipse(pvInBodyFrame);
    final Vector3D gpP = gpFirst.getPosition();
    final double gr = MathArrays.linearCombination(gpP.getX(), meridian.getX(), gpP.getY(), meridian.getY());
    final double gz = gpP.getZ();

    // topocentric frame
    final Vector3D east = new Vector3D(-meridian.getY(), meridian.getX(), 0);
    final Vector3D zenith = new Vector3D(gr * getC() / getA(), meridian, gz * getA() / getC(), Vector3D.PLUS_K)
            .normalize();
    final Vector3D north = Vector3D.crossProduct(zenith, east);

    // set up the ellipse corresponding to second principal curvature in the zenith/east plane
    final Ellipse secondPrincipalCurvature = getPlaneSection(gpP, north);
    final TimeStampedPVCoordinates gpSecond = secondPrincipalCurvature.projectToEllipse(pvInBodyFrame);

    final Vector3D gpV = gpFirst.getVelocity().add(gpSecond.getVelocity());
    final Vector3D gpA = gpFirst.getAcceleration().add(gpSecond.getAcceleration());

    // moving projected point
    final TimeStampedPVCoordinates groundPV = new TimeStampedPVCoordinates(pv.getDate(), gpP, gpV, gpA);

    // transform moving projected point back to initial frame
    return toBody.getInverse().transformPVCoordinates(groundPV);

}