Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Metoda care calculeaza viteza cu care se deplaseaza intre 2 coordonate
     * date(Lat+long) intr-un interval de timp [time_1,time_2]. Calculam
     * distanta dintre cele doua coordonate folosind formula " Great-circle
     * distance" viteza = distanta transformata in m/diferenta dintre cei 2
     * timpi primiti ca parametru
     */
    public static double computeSpeed(double lat_1, double long_1, long time_1, double lat_2, double long_2,
            long time_2) {
        double speed; // speed->m/s
        double distanceKm;
        double distanceM;
        long time;
        double r = 6378.137;

        double e = (double) Math.acos(
                Math.sin(lat_1) * Math.sin(lat_2) + Math.cos(lat_1) * Math.cos(lat_2) * Math.cos(long_2 - long_1));
        e = e / 180 * (double) Math.PI;
        distanceKm = e * r;
        distanceM = distanceKm * 1000;
        time = (time_2 - time_1) / 1000;
        speed = distanceM / time;

        return speed;
    }
}