2016-03-03 145 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