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

📄 greatcircle.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *       */    final public static float[] great_circle(float phi1, float lambda0,                                             float phi, float lambda, int n,                                             boolean include_last) {        // number of points to generate        int end = include_last ? n + 1 : n;        end <<= 1;//*2 for pairs        // calculate a bunch of stuff for later use        float cosphi = (float) Math.cos(phi);        float cosphi1 = (float) Math.cos(phi1);        float sinphi1 = (float) Math.sin(phi1);        float ldiff = lambda - lambda0;        float p2diff = (float) Math.sin(((phi - phi1) / 2));        float l2diff = (float) Math.sin((ldiff) / 2);        // calculate spherical distance        float c = 2.0f * (float) Math.asin((float) Math.sqrt(p2diff * p2diff                + cosphi1 * cosphi * l2diff * l2diff));        // calculate spherical azimuth        float Az = (float) Math.atan2(cosphi * (float) Math.sin(ldiff),                (cosphi1 * (float) Math.sin(phi) - sinphi1 * cosphi                        * (float) Math.cos(ldiff)));        float cosAz = (float) Math.cos(Az);        float sinAz = (float) Math.sin(Az);        // generate the great circle line        float[] points = new float[end];        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;        }        //      Debug.output("Calculating GreatCircle: ");        //      for (int i = 0; i< points.length; i++) {        //          Debug.output("(" + ProjMath.radToDeg(points[i].lat) + "," +        //                             ProjMath.radToDeg(points[i].lon) + ") ");        //      }        return points;    }//great_circle()    /**     * Calculate partial earth circle on the sphere.     * <p>     * Returns n float lat,lon pairs at arc distance c from point at     * phi1,lambda0.     * <p>     *      * @param phi1 latitude in radians of center point     * @param lambda0 longitude in radians of center point     * @param c arc radius in radians (0 &lt; c &lt; PI)     * @param s starting angle in radians. North up is zero.     * @param e angular extent in radians, clockwise right from     *        starting angle.     * @param n number of points along circle edge to calculate     * @return float[n] radian lat,lon pairs along earth circle     *       */    final public static float[] earth_circle(float phi1, float lambda0,                                             float c, float s, float e, int n) {        return earth_circle(phi1, lambda0, c, s, e, n, new float[n << 1]);    }    /**     * Calculate earth circle on the sphere.     * <p>     * Returns n float lat,lon pairs at arc distance c from point at     * phi1,lambda0.     * <p>     *      * @param phi1 latitude in radians of center point     * @param lambda0 longitude in radians of center point     * @param c arc radius in radians (0 &lt; c &lt; PI)     * @param n number of points along circle edge to calculate     * @return float[n] radian lat,lon pairs along earth circle     *       */    final public static float[] earth_circle(float phi1, float lambda0,                                             float c, int n) {        return earth_circle(phi1,                lambda0,                c,                0.0f,                MoreMath.TWO_PI,                n,                new float[n << 1]);    }    /**     * Calculate earth circle in the sphere.     * <p>     * Returns n float lat,lon pairs at arc distance c from point at     * phi1,lambda0.     * <p>     *      * @param phi1 latitude in radians of center point     * @param lambda0 longitude in radians of center point     * @param c arc radius in radians (0 &lt; c &lt; PI)     * @param n number of points along circle edge to calculate     * @param ret_val float[] ret_val array of n*2 number of points     *        along circle edge to calculate     * @return float[n] radian lat,lon pairs along earth circle     *       */    final public static float[] earth_circle(float phi1, float lambda0,                                             float c, int n, float[] ret_val) {        return earth_circle(phi1, lambda0, c, 0.0f, MoreMath.TWO_PI, n, ret_val);    }    /**     * Calculate earth circle in the sphere.     * <p>     * Returns n float lat,lon pairs at arc distance c from point at     * phi1,lambda0.     * <p>     *      * @param phi1 latitude in radians of center point.     * @param lambda0 longitude in radians of center point.     * @param c arc radius in radians (0 &lt; c &lt; PI).     * @param s starting angle in radians. North up is zero.     * @param e angular extent in radians, clockwise right from     *        starting angle.     * @param n number of points along circle edge to calculate.     * @param ret_val float[] ret_val array of n*2 number of points     *        along circle edge to calculate.     * @return float[n] radian lat,lon pairs along earth circle.     *       */    final public static float[] earth_circle(float phi1, float lambda0,                                             float c, float s, float e, int n,                                             float[] ret_val) {        float Az, cosAz, sinAz;        float cosphi1 = (float) Math.cos(phi1);        float sinphi1 = (float) Math.sin(phi1);        float sinc = (float) Math.sin(c);        float cosc = (float) Math.cos(c);        if (n < 2) n = 2; // Safety to avoid / by zero later.        int end = n << 1;//*2        // Only want to create a new return float array if there was a        // null one passed in, or if the number of desired coordinates        // is bigger than what ret_val is currently allocated for.        if (ret_val == null || end > ret_val.length) {            ret_val = new float[end];        }        float inc = e / (n - 1);        Az = s;        // generate the points in clockwise order (conforming to        // internal standard!)        for (int i = 0; i < end; i += 2, Az += inc) {            cosAz = (float) Math.cos(Az);            sinAz = (float) Math.sin(Az);            ret_val[i] = (float) Math.asin(sinphi1 * cosc + cosphi1 * sinc                    * cosAz);            ret_val[i + 1] = (float) Math.atan2(sinc * sinAz, cosphi1 * cosc                    - sinphi1 * sinc * cosAz)                    + lambda0;        }        return ret_val;    }    /*     * testing public final static void main (String[] args) { double     * phi1 = 34.3; double lambda0 = 130.299; double phi = -24; double     * lambda = 33.23;     *      * float dist_sphere = spherical_distance (     * ProjMath.degToRad((float)phi1),     * ProjMath.degToRad((float)lambda0),     * ProjMath.degToRad((float)phi), ProjMath.degToRad((float)lambda) ); //     * meters dist_sphere =     * Planet.wgs84_earthEquatorialCircumferenceMeters*(dist_sphere/MoreMath.TWO_PI);     * Debug.output("sphere distance="+dist_sphere/1000f+" km");     *      * AziDist invVar = ellipsoidalAziDist (     * Planet.wgs84_earthEquatorialRadiusMeters,//major in meters     * Planet.wgs84_earthFlat, //     * Planet.international1974_earthEquatorialRadiusMeters,//major in     * meters // Planet.international1974_earthFlat,     * ProjMath.degToRad(phi1), ProjMath.degToRad(lambda0),     * ProjMath.degToRad(phi), ProjMath.degToRad(lambda), new     * AziDist() ); Debug.output("ellipsoid     * distance="+invVar.distance/1000d+" km"); }     */}

⌨️ 快捷键说明

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