Android Open Source - MapsMeasure Math Util






From Project

Back to project page MapsMeasure.

License

The source code is released under:

Apache License

If you think the Android project MapsMeasure listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013 Google Inc./*  ww  w. ja  va2  s. co  m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.maps.android;

import static java.lang.Math.asin;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.sqrt;

/**
 * Utility functions that are used my both PolyUtil and SphericalUtil.
 */
class MathUtil {

    /**
     * Returns haversine(angle-in-radians).
     * hav(x) == (1 - cos(x)) / 2 == sin(x / 2)^2.
     */
    private static double hav(double x) {
        double sinHalf = sin(x * 0.5);
        return sinHalf * sinHalf;
    }

    /**
     * Computes inverse haversine. Has good numerical stability around 0.
     * arcHav(x) == acos(1 - 2 * x) == 2 * asin(sqrt(x)).
     * The argument must be in [0, 1], and the result is positive.
     */
    static double arcHav(double x) {
        return 2 * asin(sqrt(x));
    }


    /**
     * Returns hav() of distance from (lat1, lng1) to (lat2, lng2) on the unit sphere.
     */
    static double havDistance(double lat1, double lat2, double dLng) {
        return hav(lat1 - lat2) + hav(dLng) * cos(lat1) * cos(lat2);
    }
}




Java Source Code List

com.google.maps.android.MathUtil.java
com.google.maps.android.SphericalUtil.java
de.j4velin.mapsmeasure.DeleteAdapter.java
de.j4velin.mapsmeasure.Dialogs.java
de.j4velin.mapsmeasure.DrawerListAdapter.java
de.j4velin.mapsmeasure.GeocoderTask.java
de.j4velin.mapsmeasure.Map.java
de.j4velin.mapsmeasure.Util.java
de.j4velin.mapsmeasure.wrapper.API17Wrapper.java
de.j4velin.mapsmeasure.wrapper.API8Wrapper.java