⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 greatcircle.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/proj/GreatCircle.java,v $// $RCSfile: GreatCircle.java,v $// $Revision: 1.5.2.2 $// $Date: 2005/01/10 17:06:45 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.proj;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.MoreMath;/** * Methods for calculating great circle and other distances on the * sphere and ellipsoid. * <p> * Spherical equations taken from John Synder's <i>Map Projections --A * Working Manual </i>, pp29-31. <br> * Latitude/longitude arguments must be in valid radians: * -PI&lt;=lambda&lt;PI, -PI/2&lt;=phi&lt;=PI/2 */public class GreatCircle {    // cannot construct    private GreatCircle() {}    /**     * Determine azimuth and distance on the ellipsoid.     *      * @param a Semi-major axis of ellipsoid     * @param finv flattening of the ellipsoid (WGS84 is 1/298.257)     * @param glat1 Latitude of from station     * @param glon1 Longitude of from station     * @param glat2 Latitude of to station     * @param glon2 Longitude of to station     * @param ret_val AziDist struct     * @return AziDist ret_val struct with azimuth and distance     * @deprecated this has been yanked until we have a more stable     *             and documented algorithm     */    public final static AziDist ellipsoidalAziDist(double a, double finv,                                                   double glat1, double glon1,                                                   double glat2, double glon2,                                                   AziDist ret_val) {        return null;    }    /**     * Calculate spherical arc distance between two points.     * <p>     * Computes arc distance `c' on the sphere. equation (5-3a). (0     * &lt;= c &lt;= PI)     * <p>     *      * @param phi1 latitude in radians of start point     * @param lambda0 longitude in radians of start point     * @param phi latitude in radians of end point     * @param lambda longitude in radians of end point     * @return float arc distance `c'     *       */    final public static float spherical_distance(float phi1, float lambda0,                                                 float phi, float lambda) {        float pdiff = (float) Math.sin(((phi - phi1) / 2f));        float ldiff = (float) Math.sin((lambda - lambda0) / 2f);        float rval = (float) Math.sqrt((pdiff * pdiff) + (float) Math.cos(phi1)                * (float) Math.cos(phi) * (ldiff * ldiff));        return 2.0f * (float) Math.asin(rval);    }    /**     * Calculate spherical azimuth between two points.     * <p>     * Computes the azimuth `Az' east of north from phi1, lambda0     * bearing toward phi and lambda. (5-4b). (-PI &lt;= Az &lt;= PI).     * <p>     *      * @param phi1 latitude in radians of start point     * @param lambda0 longitude in radians of start point     * @param phi latitude in radians of end point     * @param lambda longitude in radians of end point     * @return float azimuth east of north `Az'     *       */    final public static float spherical_azimuth(float phi1, float lambda0,                                                float phi, float lambda) {        float ldiff = lambda - lambda0;        float cosphi = (float) Math.cos(phi);        return (float) Math.atan2(cosphi * (float) Math.sin(ldiff),                ((float) Math.cos(phi1) * (float) Math.sin(phi) - (float) Math.sin(phi1)                        * cosphi * (float) Math.cos(ldiff)));    }    /**     * Calculate point at azimuth and distance from another point.     * <p>     * Returns a LatLonPoint at arc distance `c' in direction `Az'     * from start point.     * <p>     *      * @param phi1 latitude in radians of start point     * @param lambda0 longitude in radians of start point     * @param c arc radius in radians (0 &lt; c &lt;= PI)     * @param Az azimuth (direction) east of north (-PI &lt;= Az &lt;     *        PI)     * @return LatLonPoint     *       */    final public static LatLonPoint spherical_between(float phi1,                                                      float lambda0, float c,                                                      float Az) {        float cosphi1 = (float) Math.cos(phi1);        float sinphi1 = (float) Math.sin(phi1);        float cosAz = (float) Math.cos(Az);        float sinAz = (float) Math.sin(Az);        float sinc = (float) Math.sin(c);        float cosc = (float) Math.cos(c);        return new LatLonPoint(ProjMath.radToDeg((float) Math.asin(sinphi1                * cosc + cosphi1 * sinc * cosAz)), ProjMath.radToDeg((float) Math.atan2(sinc                * sinAz,                cosphi1 * cosc - sinphi1 * sinc * cosAz)                + lambda0));    }    /**     * Calculate point between two points.     * <p>     * Same as spherical_between() above except it calculates n equal     * segments along the length of c.     * <p>     *      * @param phi1 latitude in radians of start point     * @param lambda0 longitude in radians of start point     * @param c arc radius in radians (0 &lt; c &lt;= PI)     * @param Az azimuth (direction) east of north (-PI &lt;= Az &lt;     *        PI)     * @param n number of points along great circle edge to calculate     * @return float[n+1] radian lat,lon pairs     *       */    final public static float[] spherical_between(float phi1, float lambda0,                                                  float c, float Az, int n) {        // full constants for the computation        float cosphi1 = (float) Math.cos(phi1);        float sinphi1 = (float) Math.sin(phi1);        float cosAz = (float) Math.cos(Az);        float sinAz = (float) Math.sin(Az);        int end = n << 1;        // new radian points        float[] points = new float[end + 2];        points[0] = phi1;        points[1] = lambda0;        float inc = c / n;        c = inc;        for (int i = 2; i <= end; i += 2, c += inc) {            // partial constants            float sinc = (float) Math.sin(c);            float cosc = (float) Math.cos(c);            // generate new point            points[i] = (float) Math.asin(sinphi1 * cosc + cosphi1 * sinc                    * cosAz);            points[i + 1] = (float) Math.atan2(sinc * sinAz, cosphi1 * cosc                    - sinphi1 * sinc * cosAz)                    + lambda0;        }        return points;    }    /**     * Calculate great circle between two points on the sphere.     * <p>     * Folds all computation (distance, azimuth, points between) into     * one function for optimization. returns n or n+1 pairs of     * lat,lon on great circle between lat-lon pairs.     * <p>     *      * @param phi1 latitude in radians of start point     * @param lambda0 longitude in radians of start point     * @param phi latitude in radians of end point     * @param lambda longitude in radians of end point     * @param n number of segments     * @param include_last return n or n+1 segments     * @return float[n] or float[n+1] radian lat,lon pairs

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -