2017-12-04 6 views
1

私の与えられた点から一定の距離ですべての経度と緯度を生成するJavaプログラムを作成しています。距離は正確に2000kmでなければなりません。与えられた緯度と経度から一定の距離から無作為なジオポイントを生成する

これは私のコード

public static void getLocation(double x0, double y0, int meters) { 
     Random random = new Random(); 

     // Convert radius from meters to degrees 
     double radiusInDegrees = meters/111000f; 

     double u = random.nextDouble(); 
     double v = random.nextDouble(); 
     double w = radiusInDegrees * Math.sqrt(u); 
     double t = 2 * Math.PI * v; 
     double x = w * Math.cos(t); 
     double y = w * Math.sin(t); 

     // Adjust the x-coordinate for the shrinking of the east-west distances 
     // double new_x = x/Math.cos(Math.toRadians(y0)); 

     double foundLongitude = x + x0; 
     double foundLatitude = y + y0; 
     System.out.println("Longitude: " + foundLongitude + " Latitude: " + foundLatitude); 
    } 

どのように私はすべてのポイントが円を形成するように、GEOポイントから等距離を生成するのですか?

+0

LETベアリング追加する必要が正しい、私たちは、あなたが円の全周に沿った点の座標を取得したい地理座標Xと点Yと半径Rを持っていると言いますか? –

+0

yupppp ........... – user2399158

+0

ランダムベアリングを選択し、距離と方程式を使用して目的地の緯度/経度を計算します。 [この回答](https://stackoverflow.com/questions/10119479/calculating-lat-and-long-from-bearing-and-distance)には1つの解決策があります。いくつかの詳細[ここ](https://www.movable-type.co.uk/scripts/latlong.html)。 – teppic

答えて

0
public static void generatePoint(double latitude, double longitude, double distanceInMetres, double bearing) { 
     Random random = new Random(); 

     //int bear = random.nextInt(360); 
     double brngRad = Math.toRadians(bearing); 
     double latRad = Math.toRadians(latitude); 
     double lonRad = Math.toRadians(longitude); 
     int earthRadiusInMetres = 6371000; 
     double distFrac = distanceInMetres/earthRadiusInMetres; 

     double latitudeResult = Math.asin(Math.sin(latRad) * Math.cos(distFrac) + Math.cos(latRad) * Math.sin(distFrac) * Math.cos(brngRad)); 
     double a = Math.atan2(Math.sin(brngRad) * Math.sin(distFrac) * Math.cos(latRad), Math.cos(distFrac) - Math.sin(latRad) * Math.sin(latitudeResult)); 
     double longitudeResult = (lonRad + a + 3 * Math.PI) % (2 * Math.PI) - Math.PI; 

     System.out.println("bearing: "+bearing+ ", latitude: " + Math.toDegrees(latitudeResult) + ", longitude: " + Math.toDegrees(longitudeResult)); 
    } 

関連する問題