Search in sources :

Example 21 with DoubleDouble

use of org.apache.sis.internal.util.DoubleDouble in project sis by apache.

the class DefaultEllipsoid method flatteningDifference.

/**
 * Returns the difference between the flattening factor of two ellipsoids.
 * This method returns 0 if the two ellipsoids are equal.
 *
 * <div class="note"><b>Example:</b>
 * {@code WGS84.flatteningDifference(ED50)} returns approximatively 1.41927E-05. This information is a parameter of
 * {@linkplain org.apache.sis.referencing.operation.transform.MolodenskyTransform Molodensky transformations}.</div>
 *
 * @param  other  the other ellipsoid from which to get flattening difference.
 * @return (<var>other</var> ellipsoid flattening) - (<var>this</var> ellipsoid flattening).
 *
 * @since 0.7
 */
public double flatteningDifference(final Ellipsoid other) {
    final DoubleDouble f = flattening(other);
    f.subtract(flattening(this));
    return f.value;
}
Also used : DoubleDouble(org.apache.sis.internal.util.DoubleDouble)

Example 22 with DoubleDouble

use of org.apache.sis.internal.util.DoubleDouble in project sis by apache.

the class TimeDependentBWP method param.

/**
 * Returns the parameter at the given index. If this {@code BursaWolfParameters} is time-dependent,
 * then the returned value shall be corrected for the given period.
 *
 * @param  index   0 for {@code tX}, 1 for {@code tY}, <i>etc.</i> in {@code TOWGS84[…]} order.
 * @param  period  the value computed by {@link #period(Date)}, or {@code null}.
 */
@Override
final DoubleDouble param(final int index, final DoubleDouble period) {
    final DoubleDouble p = super.param(index, period);
    if (period != null) {
        final double value = period.value;
        final double error = period.error;
        final double d;
        switch(index) {
            case 0:
                d = dtX;
                break;
            case 1:
                d = dtY;
                break;
            case 2:
                d = dtZ;
                break;
            case 3:
                d = drX;
                break;
            case 4:
                d = drY;
                break;
            case 5:
                d = drZ;
                break;
            case 6:
                d = ddS;
                period.multiply(1000, 0);
                break;
            default:
                throw new AssertionError(index);
        }
        period.multiply(d);
        p.add(period);
        period.value = value;
        period.error = error;
    }
    return p;
}
Also used : DoubleDouble(org.apache.sis.internal.util.DoubleDouble)

Example 23 with DoubleDouble

use of org.apache.sis.internal.util.DoubleDouble in project sis by apache.

the class TimeDependentBWP method period.

/**
 * Returns the elapsed time from the {@linkplain TimeDependentBWP#getTimeReference() reference time}
 * to the given date in millennium, or {@code null} if none.
 */
@Override
final DoubleDouble period(final Date time) {
    if (time != null) {
        final long millis = time.getTime() - timeReference;
        if (millis != 0) {
            // Returns null for 0 as an optimization.
            final DoubleDouble period = verbatim(millis);
            period.divide(1000 * JULIAN_YEAR_LENGTH, 0);
            return period;
        }
    }
    return null;
}
Also used : DoubleDouble(org.apache.sis.internal.util.DoubleDouble)

Example 24 with DoubleDouble

use of org.apache.sis.internal.util.DoubleDouble in project sis by apache.

the class ConformalProjectionTest method testMath.

/**
 * Tests a few formulas used by the Mercator projection in the spherical case.
 * This is a little bit more a Java test than an Apache SIS test (or to be more
 * accurate, a test of our understanding of the {@code java.lang.Math} library).
 *
 * {@preformat text
 *   Forward:  y = log(tan(π/4 + φ/2))
 *   Inverse:  φ = π/2 - 2*atan(exp(-y))
 * }
 */
@Test
public void testMath() {
    assertEquals("Forward 0°N", 0, log(tan(PI / 4)), TOLERANCE);
    assertEquals("Inverse 0 m", 0, PI / 2 - 2 * atan(exp(0)), TOLERANCE);
    assertEquals("Forward 90°S", NEGATIVE_INFINITY, log(tan(0)), TOLERANCE);
    assertEquals("Forward (90+ε)°S", NaN, log(tan(-nextUp(0))), TOLERANCE);
    assertEquals("Inverse −∞", PI / 2, atan(exp(-NEGATIVE_INFINITY)), TOLERANCE);
    assertEquals("Inverse −∞ appr.", PI / 2, atan(exp(LN_INFINITY + 1)), TOLERANCE);
    /*
         * tan(PI/2) do not produces positive infinity as we would expect, because there is no
         * exact representation of PI in base 2.  Experiments show that we get some high value
         * instead (1.633E+16 on my machine, having a logarithm of 37.332).
         */
    assertTrue("Forward 90°N", 1E+16 < tan(PI / 2));
    assertTrue("Forward 90°N", LN_INFINITY < log(tan(PI / 2)));
    assertEquals("Forward (90+ε)°N", NaN, log(tan(nextUp(PI / 2))), TOLERANCE);
    assertEquals("Inverse +∞", 0, atan(exp(NEGATIVE_INFINITY)), TOLERANCE);
    assertEquals("Inverse +∞ appr.", 0, atan(exp(-(LN_INFINITY + 1))), TOLERANCE);
    /*
         * Some checks performed in our projection implementations assume that
         * conversion of 90° to radians give exactly Math.PI/2.
         */
    final DoubleDouble dd = DoubleDouble.createDegreesToRadians();
    dd.multiply(90);
    assertEquals(PI / 2, dd.value, 0.0);
    assertEquals(PI / 2, toRadians(90), 0.0);
}
Also used : DoubleDouble(org.apache.sis.internal.util.DoubleDouble) Test(org.junit.Test)

Example 25 with DoubleDouble

use of org.apache.sis.internal.util.DoubleDouble in project sis by apache.

the class LambertConicConformalTest method verifyBelgeConstant.

/**
 * Verifies the value of the constant used in <cite>"Lambert Conic Conformal (2SP Belgium)"</cite> projection.
 *
 * @see #testLambertConicConformalBelgium()
 */
@Test
public void verifyBelgeConstant() {
    final DoubleDouble BELGE_A = (DoubleDouble) LambertConicConformal.belgeA();
    BigDecimal a = new BigDecimal(BELGE_A.value);
    a = a.add(new BigDecimal(BELGE_A.error));
    // Conversion from radians to degrees.
    a = a.multiply(new BigDecimal("57.29577951308232087679815481410517"));
    // Conversion from degrees to seconds.
    a = a.multiply(new BigDecimal(60 * 60));
    // The standard value.
    a = a.add(new BigDecimal("29.2985"));
    assertTrue(abs(a.doubleValue()) < 1E-31);
}
Also used : BigDecimal(java.math.BigDecimal) DoubleDouble(org.apache.sis.internal.util.DoubleDouble) Test(org.junit.Test)

Aggregations

DoubleDouble (org.apache.sis.internal.util.DoubleDouble)39 MatrixSIS (org.apache.sis.referencing.operation.matrix.MatrixSIS)5 Test (org.junit.Test)3 ExtendedPrecisionMatrix (org.apache.sis.internal.referencing.ExtendedPrecisionMatrix)2 DirectPosition (org.opengis.geometry.DirectPosition)2 AxisDirection (org.opengis.referencing.cs.AxisDirection)2 AffineTransform (java.awt.geom.AffineTransform)1 BigDecimal (java.math.BigDecimal)1 IncommensurableException (javax.measure.IncommensurableException)1 ParameterizedAffine (org.apache.sis.internal.referencing.j2d.ParameterizedAffine)1 Parameters (org.apache.sis.parameter.Parameters)1 Matrix4 (org.apache.sis.referencing.operation.matrix.Matrix4)1 ContextualParameters (org.apache.sis.referencing.operation.transform.ContextualParameters)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 MismatchedDimensionException (org.opengis.geometry.MismatchedDimensionException)1 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)1 MathTransform (org.opengis.referencing.operation.MathTransform)1