2016-03-03 141 views
0

我有圓心和半徑的座標。我需要知道圓圈的座標才能在KML中使用後置圓。生成KML中座標的圓半徑的座標

我寫了一個腳本,生成一個較低的位置,但是當他插入到KML中時,我會將它們插入而不是一個圓圈。幫助理解什麼是什麼?

import java.util.*; 
import java.lang.*; 
import java.io.*; 

class Codechef 
{ 
public static void main (String[] args) throws java.lang.Exception 
{ 
int[] a = new int[10]; 
double[] ar1; 
double ar2[]; 
    a[1]=5; 

    double centerLat = (44.507693* Math.PI)/180.0; //rad 
    double centerLng = (34.152739* Math.PI)/180.0; //rad   
    double dist = 1/ 6371.0; 
    double lan; 
    for (int x = 0; x <= 360; x += 1) 
    { 
     double brng = x * Math.PI/180.0;   //rad 
     double latitude = Math.asin(Math.sin(centerLat) * Math.cos(dist) + Math.cos(centerLat) * Math.sin(dist) * Math.cos(brng)); 
     double longitude = ((centerLng + Math.atan2(Math.sin(brng) * Math.sin(dist)* Math.cos(centerLat), Math.cos(dist) - Math.sin(centerLat) 
     * Math.sin(latitude))) * 180.0)/Math.PI; 
     lan=(latitude * 180.0)/Math.PI; //, longitude)); 
     System.out.println(""+lan+" "+longitude); 
    } 
} 

}

+1

真的是不可理解的 - 但是如果你表現出你正在努力實現的公式,我們也許能夠看到 – gpasch

回答

0

你的公式是正確的。下面是完整的Java代碼,用於生成圓的座標並將其輸出爲具有多邊形幾何體的KML地標。

public class Codechef { 

    public static void main(String[] args) { 

    double centerLat = Math.toRadians(44.507693); 
    double centerLng = Math.toRadians(34.152739); 
    double diameter = 1; // diameter of circle in km 
    double dist = diameter/6371.0; 

    // start generating KML 
    System.out.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"+ 
     "<Placemark><Polygon><outerBoundaryIs><LinearRing><coordinates>"); 

    for (int x = 0; x <= 360; x ++) 
    { 
     double brng = Math.toRadians(x); 
     double latitude = Math.asin(Math.sin(centerLat) * Math.cos(dist) + Math.cos(centerLat) * Math.sin(dist) * Math.cos(brng)); 
     double longitude = 
     centerLng + Math.atan2(Math.sin(brng) * Math.sin(dist)* Math.cos(centerLat), Math.cos(dist) - Math.sin(centerLat) 
      * Math.sin(latitude)) ; 
     System.out.printf(" %f,%f", Math.toDegrees(longitude), Math.toDegrees(latitude)); 
    } 
    System.out.println("</coordinates></LinearRing></outerBoundaryIs></Polygon>"); 
    System.out.println("</Placemark></kml>"); 
    } 

} 
+0

感謝,真誠的幫助我 – VasyPupkin

+0

如果幫助您的問題,那麼請標明問題與向上箭頭一樣有用在答案旁邊。這表明一個有用的答案。 – JasonM1