首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分段相交: Mercator投影求nan值

分段相交: Mercator投影求nan值
EN

Stack Overflow用户
提问于 2013-12-15 20:47:10
回答 1查看 418关注 0票数 0

我对mercator投影有一点小问题,当我在纬度上投影时,我得到了nan值.

我的代码来自于这个问题:ConvertLATLONGTOXY

代码语言:javascript
复制
private static List<Point2D.Double> LatLongConvertionToXY(List<GeoPoint> coordinates) {
        List<Point2D.Double> xys = new ArrayList<Point2D.Double>();

        /*MercatorProjection projection = new MercatorProjection();*/
        Log.i("LATLONG2RAD", "Nouvelle conversion");
        for (GeoPoint coordinate : coordinates) {
            double latitude = Double.valueOf(coordinate.getLatitudeE6());
            double longitude = Double.valueOf(coordinate.getLongitudeE6());

            // convert to radian
            latitude = latitude * Math.PI / 180;
            longitude = longitude * Math.PI / 180;
            Log.i("LATLONG2RAD", String.valueOf(latitude)+" : "+String.valueOf(longitude));
            /*Point2D.Double d = projection.project(longitude,latitude,
                    new Point2D.Double());*/
            Point2D.Double d=new Point2D.Double();
            double QUARTERPI = Math.PI / 4.0;
            d.x = longitude;
            d.y = Math.log(Math.tan(QUARTERPI + 0.5 * latitude));
            Log.i("PointLATLONG YX", String.valueOf(d.y)+" : "+String.valueOf(d.x));
            xys.add(d);
        }

        return xys;
    }

返回值的示例: 12-15 21:42:27.165: I/LATLONG2RAD(32629):Nouvelle转换

12-15 21:42:27.165: I/LATLONG2RAD(32629):LAT 782581.6732236275 : LONG -10478.398323613315

12-15 21:42:27.165: I/LATLONG2RAD(32629):LAT 782581.6732236275 : LONG -10478.398323613315

12-15 21:42:27.165: I/LATLONG2RAD(32629):LAT 782587.2931838189 : LONG -10476.478461436123

12-15 21:42:27.165: I/LATLONG2RAD(32629):LAT 782571.9517396939 : LONG -10476.478461436123

用于投影的返回值:

12-15 21:42:27.165: I/PointLATLONG YX(32629):NaN:-10478.398323613315

12-15 21:42:27.165: I/PointLATLONG YX(32629):NaN:-10478.398323613315

12-15 21:42:27.165: I/PointLATLONG YX(32629):NaN:-10476.478461436123

12-15 21:42:27.165: I/PointLATLONG YX(32629):1.7354151627839085:-10476.478461436123

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-15 23:08:16

最后,JRowan --没关系--我读了代码,然后用投影法mercator重试了,我发现我的问题--用osm geopoint -我的值第一个到nan值--我的值在微观上,而不是双倍的:

我的新代码:

代码语言:javascript
复制
private static List<Point2D.Double> LatLongConvertionToXY(List<GeoPoint> coordinates) {
        List<Point2D.Double> xys = new ArrayList<Point2D.Double>();

        MercatorProjection projection = new MercatorProjection();
        Log.i("LATLONG2RAD", "New");
        for (GeoPoint coordinate : coordinates) {
            double latitude = Double.valueOf(coordinate.getLatitudeE6());
            double longitude = Double.valueOf(coordinate.getLongitudeE6());

            //to decimal
            latitude=latitude / 1E6;
            longitude=longitude / 1E6;
            Log.i("LATLONG2RAD", "BEFORE RADIAN "+String.valueOf(latitude)+" : "+String.valueOf(longitude));
            //convert to radian
            latitude = latitude * Math.PI / 180;
            longitude = longitude * Math.PI / 180;
            //Log.i("LATLONG2RAD", String.valueOf(latitude)+" : "+String.valueOf(longitude));
            Point2D.Double d = projection.project(longitude,latitude,
                    new Point2D.Double());

            Log.i("LATLONG2RAD"," Y X "+ String.valueOf(d.y)+" : "+String.valueOf(d.x));
            xys.add(d);
        }

        return xys;
    }

这种预测似乎是好的:

12-15 22:41:40.257: I/LATLONG2RAD(1138):y X 0.8505407464143129 : 0.11730010582132741

12-15 22:41:40.267: I/LATLONG2RAD(1138):y X 0.8506068875926396 : 0.11715522604011937

12-15 22:41:40.267: I/LATLONG2RAD(1138):y X 0.8505923208133851 : 0.1172139738227415

12-15 22:41:40.267: I/LATLONG2RAD(1138):y X 0.8505727537288554 : 0.1172139738227415

但是现在另一个pb使用的是交集的计算:

代码语言:javascript
复制
public static GeoPoint intersectionV1bis(List<GeoPoint> mGeoPoints) {
        if (mGeoPoints.size() == 0 || mGeoPoints.size() > 4)
            return null;
        List<Point2D.Double> coordinates = LatLongConvertionToXY(mGeoPoints);
        double x1 = coordinates.get(0).x;
        double y1 = coordinates.get(0).y;
        double x2 = coordinates.get(1).x;
        double y2 = coordinates.get(1).y;
        double x3 = coordinates.get(2).x;
        double y3 = coordinates.get(2).y;
        double x4 = coordinates.get(3).x;
        double y4 = coordinates.get(3).y;
        double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
        if (d == 0){
            Log.i("INTERSECT V1","Segments parallels");
            return null;
        }

        double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2)
                * (x3 * y4 - y3 * x4))
                / d;
        double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2)
                * (x3 * y4 - y3 * x4))
                / d;



        GeoPoint p = new GeoPoint(xi, yi);
        Log.i("INTERSECT","xi long"+String.valueOf(xi)+" : yi lat"+String.valueOf(yi));
        if (xi < Math.min(x1, x2) || xi > Math.max(x1, x2)){
            Log.i("INTERSECT V1","Not in segment 1");
            return null;
        }

        if (xi < Math.min(x3, x4) || xi > Math.max(x3, x4)){
            Log.i("INTERSECT V1","Not in segment 2");
            return null;
        }
        Log.i("INTERSECT","Intersection");
        return p;
    }

12-15 22:41:40.267: I/INTERSECT(1138):xi 1138 0.11721397382272966:彝文0.8505800677870533

在开放的街道地图上,直线段相交,但代码拒绝,我不明白为什么。A点和B点是我最后和新的位置,C和D是点E的左右两个点(在第一个交叉点上按下按钮来定义当前位置的+90和-90 ),即在A和B之间。

我一直使用仿真器有相同的位置,但是当我试图计算A和B之间的第二次交叉时,E不是在C和D段上。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20599593

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档