2013-12-15 35 views
0

我有墨卡託投影一個小問題,我越來越楠值當我嘗試緯度投影...段路口:墨卡託投影越來越楠價值

我從這個問題codederived: ConvertLATLONGTOXY

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):中篇小說轉換

12-15 21:42:27.165:I/LATLONG2RAD(32629):LAT 782581.6732236275:L ONG -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.3 98323613315

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

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

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

+0

數值小於0的Math.log()將返回NaN – JRowan

+0

thx我認爲這個算法不會幫助我,我從java地圖庫中使用了mercator投影類,並且這個返回值也是,我很少迷路,你可以在註釋中看到上面這段代碼。任何想法 ? – WhatsUp

+0

你沒有使用它如何使用它在那篇文章中他有其他的東西,如://我們需要確定min X和Y值的原因是因爲要繪製地圖,我們需要抵消位置 這樣就不會有X和Y的負值 minXY.x =(minXY.x == -1)? xy.x:Math.min(minXY.x,xy.x); minXY.y =(minXY.y == -1)? xy.y:Math.min(minXY.y,xy.y);檢查,你應該回去重讀他使用的代碼。 – JRowan

回答

0

最後,JRowan這沒關係,我重新閱讀代碼,和我一起與Java地圖圖書館試投影mercator,並且我發現我的問題是第一個使用osm的地點值,我的值是微程度不是雙倍:

我的新的代碼:

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):YX 0.8505407464143129:0.11730010582132741

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

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

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

但現在的其他PB與交點的計算:

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 long0.11721397382272966:yi lat0.8505800677870533

在打開的街道地圖上,線段相交,但代碼表示否,我不明白爲什麼。A點和B點是我的最後一個和新的位置,C和D點在E點的左右兩點(通過按下第一個十字路口上的按鈕,當前位置的方位爲+90和-90),即A和B

之間我使用仿真器具有薩姆斯位置所有的時間,但是當我嘗試來計算A和B和betweeen C和d之間的第二交叉E,E不是在段C和d