Java tutorial
//package com.java2s; public class Main { /*** * Fetch the raw estimated time enroute given the input parameters * @param distance - how far to the target * @param speed - how fast we are moving * @param bearing - direction to target * @param heading - direction of movement * @return int value of HR * 100 + MIN for the ete, -1 if not applicable */ private static int fetchRawEte(double distance, double speed, double bearing, double heading) { // We can't assume that we are heading DIRECTLY for the destination, so // we need to figure out the multiply factor by taking the COS of the difference // between the bearing and the heading. double angDif = angularDifference(heading, bearing); // If the difference is 90 or greater, then ETE means nothing as we are not // closing on the target if (angDif >= 90) return -1; // Calculate the actual relative speed closing on the target double xFactor = Math.cos(angDif * Math.PI / 180); double eteTotal = distance / (speed * xFactor); // Break that down into hours and minutes int eteHr = (int) eteTotal; int eteMin = (int) Math.round((eteTotal - (double) eteHr) * 60); // account for the minutes being 60 if (eteMin >= 60) { eteHr++; eteMin -= 60; } // Return with our estimate return eteHr * 100 + eteMin; } /** Calculate the absolute angular difference between the two headings * * @param hdg angle 1 in degrees (typically the heading) * @param brg angle 2 in degrees (typically the bearing) * @return difference between hdg and brg in degrees */ public static double angularDifference(double hdg, double brg) { double absDiff = Math.abs(hdg - brg); if (absDiff > 180) { return 360 - absDiff; } return absDiff; } }