我有圆心和半径的坐标。我需要知道圆的坐标才能在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 );
}
}
}
最佳答案
您的公式是正确的。这是完整的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>");
}
}