Search in sources :

Example 1 with LongitudePair

use of au.gov.amsa.util.navigation.Position.LongitudePair in project risky by amsa-code.

the class GridTraversor method nextPointCrossingLatitude.

private Position nextPointCrossingLatitude(Position a, Position b, double leftLon, double rightLon, double targetLat, double bearingDegrees) {
    LongitudePair lonCrossingCandidates = a.getLongitudeOnGreatCircle(b, targetLat);
    if (lonCrossingCandidates != null) {
        double lonCrossing;
        // choose candidate closest in longitude to point a along path to b
        boolean candidate1ok = leftLon <= lonCrossingCandidates.getLon1() && lonCrossingCandidates.getLon1() <= rightLon && !(lonCrossingCandidates.getLon1() == a.getLon() && targetLat == a.getLat());
        boolean candidate2ok = leftLon <= lonCrossingCandidates.getLon2() && lonCrossingCandidates.getLon2() <= rightLon && !(lonCrossingCandidates.getLon2() == a.getLon() && targetLat == a.getLat());
        if (candidate1ok && candidate2ok) {
            // choose the best of the candidates
            // no units used in calculations because only doing comparisons
            // so don't care if it's km or nautical miles
            double distance1ToB = new Position(targetLat, lonCrossingCandidates.getLon1()).getDistanceToKm(b);
            double distance2ToB = new Position(targetLat, lonCrossingCandidates.getLon2()).getDistanceToKm(b);
            double distanceAToB = a.getDistanceToKm(b);
            if (distance1ToB > distanceAToB)
                candidate1ok = false;
            if (distance2ToB > distanceAToB)
                candidate2ok = false;
            if (candidate1ok && candidate2ok) {
                if (distance1ToB < distance2ToB) {
                    candidate1ok = false;
                } else
                    candidate2ok = false;
            }
            if (candidate1ok)
                lonCrossing = lonCrossingCandidates.getLon1();
            else if (candidate2ok)
                lonCrossing = lonCrossingCandidates.getLon2();
            else
                // neither of the candidates are on the way to b!
                return null;
        } else if (candidate1ok) {
            lonCrossing = lonCrossingCandidates.getLon1();
        } else if (candidate2ok)
            lonCrossing = lonCrossingCandidates.getLon2();
        else
            return null;
        // check that lonCrossing is on the segment a to b
        double bearingDegreesTest = bearingDegrees(a, Position.create(targetLat, lonCrossing));
        double diff = Position.getBearingDifferenceDegrees(bearingDegrees, bearingDegreesTest);
        if (Math.abs(diff) > 90)
            return null;
        return Position.create(targetLat, lonCrossing);
    } else
        return null;
}
Also used : LongitudePair(au.gov.amsa.util.navigation.Position.LongitudePair) Position(au.gov.amsa.util.navigation.Position)

Example 2 with LongitudePair

use of au.gov.amsa.util.navigation.Position.LongitudePair in project risky by amsa-code.

the class DistanceTravelledCalculatorTest method manualTestCase.

@Test
public void manualTestCase() {
    Position a = new Position(-30.8, 140.2);
    Position b = new Position(-31.7, 142.6);
    System.out.println(toPos(a).getBearingDegrees(toPos(b)));
    Options options = Options.builder().originLat(0).originLon(0).cellSizeDegrees(1.0).bounds(new Bounds(0, 100, -60, 175)).build();
    Observable<CellAndDistance> list = DistanceTravelledCalculator.getCellDistances(a, b, options);
    System.out.println("totalBearing=" + toPos(a).getBearingDegrees(toPos(b)));
    LongitudePair gcIntercept = toPos(a).getLongitudeOnGreatCircle(toPos(b), -31.0);
    System.out.println("gc long=" + gcIntercept);
    au.gov.amsa.util.navigation.Position nextPos = au.gov.amsa.util.navigation.Position.create(-31.0, gcIntercept.getLon2());
    System.out.println("bearingToFinal=" + nextPos.getBearingDegrees(toPos(b)));
    System.out.println("nextLat = " + nextPos.getLatitudeOnGreatCircle(toPos(b), 141.0));
    double totalNm = 0;
    for (CellAndDistance value : list.toList().toBlocking().single()) {
        System.out.println(value);
        totalNm += value.getDistanceNm();
    }
    assertEquals(toPos(a).getDistanceToKm(toPos(b)) / 1.852, totalNm, 0.2);
}
Also used : Options(au.gov.amsa.geo.model.Options) LongitudePair(au.gov.amsa.util.navigation.Position.LongitudePair) Position(au.gov.amsa.geo.model.Position) Bounds(au.gov.amsa.geo.model.Bounds) Test(org.junit.Test)

Example 3 with LongitudePair

use of au.gov.amsa.util.navigation.Position.LongitudePair in project risky by amsa-code.

the class PositionTest method testGetLongitudeOnGreatCircleFromLaxToJfk.

@Test
public void testGetLongitudeOnGreatCircleFromLaxToJfk() {
    Position a = Position.create(33 + 57 / 60.0, -118 - 24 / 60.0);
    Position b = Position.create(40 + 38 / 60.0, -73 - 47 / 60.0);
    System.out.println(a.getBearingDegrees(b));
    LongitudePair candidates = a.getLongitudeOnGreatCircle(b, 36 + 23.65967428 / 60.0);
    System.out.println(candidates);
    assertEquals(-111, candidates.getLon1(), PRECISION);
    assertEquals(-48.391565812643, candidates.getLon2(), PRECISION);
}
Also used : LongitudePair(au.gov.amsa.util.navigation.Position.LongitudePair) Test(org.junit.Test)

Aggregations

LongitudePair (au.gov.amsa.util.navigation.Position.LongitudePair)3 Test (org.junit.Test)2 Bounds (au.gov.amsa.geo.model.Bounds)1 Options (au.gov.amsa.geo.model.Options)1 Position (au.gov.amsa.geo.model.Position)1 Position (au.gov.amsa.util.navigation.Position)1