Returns haversine(angle-in-radians). - Java java.lang

Java examples for java.lang:Math Trigonometric Function

Description

Returns haversine(angle-in-radians).

Demo Code


//package com.java2s;
import static java.lang.Math.*;

public class Main {
    /**/*  w  w w .j av  a 2 s . c o m*/
     * Returns haversine(angle-in-radians).
     * hav(x) == (1 - cos(x)) / 2 == sin(x / 2)^2.
     */
    static double hav(double x) {
        double sinHalf = sin(x * 0.5);
        return sinHalf * sinHalf;
    }
}

Related Tutorials