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

📄 gnomonic.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Forward project a point. If the point is not within the     * viewable hemisphere, return flags in AzimuthVar variable if     * specified.     *      * @param phi float latitude in radians     * @param lambda float longitude in radians     * @param p Point     * @param azVar AzimuthVar or null     * @return Point pt     */    protected Point _forward(float phi, float lambda, Point p, AzimuthVar azVar) {        float c = hemisphere_distance(ctrLat, ctrLon, phi, lambda);        // normalize invalid point to the edge of the sphere        if (c > HEMISPHERE_EDGE) {            float az = GreatCircle.spherical_azimuth(ctrLat,                    ctrLon,                    phi,                    lambda);            if (azVar != null) {                azVar.invalid_forward = true; // set the invalid flag                azVar.current_azimuth = az; // record azimuth of this                                            // point            }            return edge_point(p, az);        }        float kPrime = 1f / (float) Math.cos(c);        float cosPhi = (float) Math.cos(phi);        float sinPhi = (float) Math.sin(phi);        float lambdaMinusCtrLon = (float) (lambda - ctrLon);        float cosLambdaMinusCtrLon = (float) Math.cos(lambdaMinusCtrLon);        float sinLambdaMinusCtrLon = (float) Math.sin(lambdaMinusCtrLon);        p.x = (int) (scaled_radius * kPrime * cosPhi * sinLambdaMinusCtrLon)                + wx;        p.y = hy                - (int) (scaled_radius * kPrime * (cosCtrLat * sinPhi - sinCtrLat                        * cosPhi * cosLambdaMinusCtrLon));        return p;    }    /**     * Inverse project x,y coordinates into a LatLonPoint.     *      * @param x integer x coordinate     * @param y integer y coordinate     * @param llp LatLonPoint     * @return LatLonPoint llp     * @see Proj#inverse(Point)     *       */    public LatLonPoint inverse(int x, int y, LatLonPoint llp) {        // convert from screen to world coordinates        x = x - wx;        y = hy - y;        //      Debug.output("Gnomonic.inverse: x,y=" + x + "," + y);        float rho = (float) Math.sqrt(x * x + y * y);        if (rho == 0f) {            Debug.message("proj", "Gnomonic.inverse: center!");            llp.setLatLon(ProjMath.radToDeg(ctrLat), ProjMath.radToDeg(ctrLon));            return llp;        }        float c = (float) Math.atan2(rho, scaled_radius);        float cosC = (float) Math.cos(c);        float sinC = (float) Math.sin(c);        // calculate latitude        float lat = (float) Math.asin(cosC * sinCtrLat                + (y * sinC * (cosCtrLat / rho)));        // calculate longitude        float lon = ctrLon                + (float) Math.atan2((x * sinC), (rho * cosCtrLat * cosC - y                        * sinCtrLat * sinC));        //      Debug.output("Gnomonic.inverse: lat,lon=" +        //                         ProjMath.radToDeg(lat) + "," +        //                         ProjMath.radToDeg(lon));        // check if point in outer space        //      if (MoreMath.approximately_equal(lat, ctrLat) &&        //             MoreMath.approximately_equal(lon, ctrLon) &&        //             (Math.abs(x-(width/2))<2) &&        //             (Math.abs(y-(height/2))<2))        if (Float.isNaN(lat) || Float.isNaN(lon)) {            Debug.message("proj", "Gnomonic.inverse(): outer space!");            lat = ctrLat;            lon = ctrLon;        }        llp.setLatLon(ProjMath.radToDeg(lat), ProjMath.radToDeg(lon));        return llp;    }    /**     * Inverse project a Point.     *      * @param pt x,y Point     * @param llp resulting LatLonPoint     * @return LatLonPoint llp     *       */    public LatLonPoint inverse(Point pt, LatLonPoint llp) {        return inverse(pt.x, pt.y, llp);    }    /**     * Check if equator is visible on screen.     *      * @return boolean     */    public boolean overEquator() {        LatLonPoint llN = inverse(width / 2, 0, new LatLonPoint());        LatLonPoint llS = inverse(width / 2, height, new LatLonPoint());        return MoreMath.sign(llN.radlat_) != MoreMath.sign(llS.radlat_);    }    /**     * Get the upper left (northernmost and westernmost) point of the     * projection.     * <p>     * Returns the upper left point (or closest equivalent) of the     * projection based on the center point and height and width of     * screen.     *      * @return LatLonPoint     */    public LatLonPoint getUpperLeft() {        LatLonPoint tmp = new LatLonPoint();        float lat, lon;        // over north pole        if (overNorthPole()) {            lat = NORTH_POLE;            lon = -DATELINE;        }        // over south pole        else if (overSouthPole()) {            lon = -DATELINE;            if (overEquator()) {                // get top center for latitude                tmp = inverse(width / 2, 0, tmp);                lat = tmp.radlat_;            } else {                // get left top corner for latitude                tmp = inverse(0, 0, tmp);                lat = tmp.radlat_;            }        }        // view in northern hemisphere        else if (ctrLat >= 0f) {            // get left top corner for longitude            tmp = inverse(0, 0, tmp);            lon = tmp.radlon_;            // get top center for latitude            tmp = inverse(width / 2, 0, tmp);            lat = tmp.radlat_;        }        // view in southern hemisphere        else {            // get left bottom corner for longitude            tmp = inverse(0, height, tmp);            lon = tmp.radlon_;            if (overEquator()) {                // get top center (for latitude)                tmp = inverse(width / 2, 0, tmp);                lat = tmp.radlat_;            } else {                // get left top corner (for latitude)                tmp = inverse(0, 0, tmp);                lat = tmp.radlat_;            }        }        tmp.setLatLon(lat, lon, true);        //      Debug.output("ul="+tmp);        return tmp;    }    /**     * Get the lower right (southeast) point of the projection.     * <p>     * Returns the lower right point (or closest equivalent) of the     * projection based on the center point and height and width of     * screen.     * <p>     * This is trivial for most cylindrical projections, but much more     * complicated for azimuthal projections.     *      * @return LatLonPoint     */    public LatLonPoint getLowerRight() {        LatLonPoint tmp = new LatLonPoint();        float lat, lon;        // over north pole        if (overNorthPole()) {            lon = DATELINE;            if (overEquator()) {                // get bottom center for latitude                tmp = inverse(width / 2, height, tmp);                lat = tmp.radlat_;            } else {                // get bottom right corner for latitude                tmp = inverse(width, height, tmp);                lat = tmp.radlat_;            }        }        // over south pole        else if (overSouthPole()) {            lat = SOUTH_POLE;            lon = DATELINE;        }        // view in northern hemisphere        else if (ctrLat >= 0f) {            // get the right top corner for longitude            tmp = inverse(width, 0, tmp);            lon = tmp.radlon_;            if (overEquator()) {                // get the bottom center (for latitude)                tmp = inverse(width / 2, height, tmp);                lat = tmp.radlat_;            } else {                // get the right bottom corner (for latitude)                tmp = inverse(width, height, tmp);                lat = tmp.radlat_;            }        }        // view in southern hemisphere        else {            // get the right bottom corner for longitude            tmp = inverse(width, height, tmp);            lon = tmp.radlon_;            // get bottom center for latitude            tmp = inverse(width / 2, height, tmp);            lat = tmp.radlat_;        }        tmp.setLatLon(lat, lon, true);        //      Debug.output("lr="+tmp);        return tmp;    }    /**     * Get the name string of the projection.     */    public String getName() {        return GnomonicName;    }}

⌨️ 快捷键说明

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