`

经纬度平面转换

 
阅读更多
package com.anyec.point;

public class Point3D {
	
	private Double x,y,z;
	
	public Point3D() {
		super();
	}

	public Point3D(Double x, Double y, Double z) {
		super();
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public Double getX() {
		return x;
	}

	public void setX(Double x) {
		this.x = x;
	}

	public Double getY() {
		return y;
	}

	public void setY(Double y) {
		this.y = y;
	}

	public Double getZ() {
		return z;
	}

	public void setZ(Double z) {
		this.z = z;
	}
	
	public static double distance(Point3D p1,Point3D p2) {
		return Math.sqrt(Math.pow(p1.getX()-p2.getX(), 2)
				+Math.pow(p1.getY()-p2.getY(), 2)
				+Math.pow(p1.getZ()-p2.getZ(), 2));
	}
	
	public  double distanceTo(Point3D p2) {
		return Math.sqrt(Math.pow(this.getX()-p2.getX(), 2)
				+Math.pow(this.getY()-p2.getY(), 2)
				+Math.pow(this.getZ()-p2.getZ(), 2));
	}
	public  double distanceTo2(Point3D p2) {
		return Math.sqrt(Math.pow(this.getX()-p2.getX(), 2)
				+Math.pow(this.getZ()-p2.getZ(), 2));
	}
	public void print() {
		System.out.println("("+x+","+y+","+z+")");
	}
	
	public static Point3D toXYZ(double lng, double lat) {
		double radius = 6378.140 * 1000 * 100;// cm
		double phi = (180 + lng) * (Math.PI / 180);
		double theta = (90 - lat) * (Math.PI / 180);
		return new Point3D(-radius * Math.sin(theta) * Math.cos(phi), radius * Math.cos(theta),
				radius * Math.sin(theta) * Math.sin(phi));
	}
	
	public static void toLngLat(Point3D p) {
		double radius = 6378.140 * 1000 * 100;// cm
		double theta = Math.acos(p.getY()/radius);
		double phi=Math.acos(p.getX()/((-radius)*Math.sin(theta)));
		double lng=180-phi*180/Math.PI;
		double lat=90-theta*180/Math.PI;
		System.out.println(lng+" "+lat);

	}
	public static void main(String[] args) {
		//toXYZ(114.439322,30.41082).print();
//		System.out.println(toXYZ(114.439322,30.41082).distanceTo2(toXYZ(114.443307,30.408674)));
//		System.out.println(toXYZ(114.439322,30.41082).distanceTo(toXYZ(114.443307,30.408674)));
		//toLngLat(toXYZ(114.439322,30.41082));
		
		//toXYZ(114.439322,30.41082);
//		Point l1=new Point(114.439322,30.41082);
//		Point l2=new Point(114.443307,30.408674);
//		Point r1=new Point(114.439365,30.410866);
		Point3D l1 = toXYZ(114.439322,30.41082);
		Point3D l2 = toXYZ(114.443307,30.408674);
		Point3D r1 = toXYZ(114.439365,30.410866);
		double d=l1.distanceTo2(l2);
		double r=300;
		double d2=Math.sqrt(Math.pow(d, 2)+Math.pow(r, 2));
		//System.out.println();
		
		Circle c1=new Circle(l1.getX(),l1.getZ(),r);
		Circle c2=new Circle(l2.getX(),l2.getZ(),d2);
		Point[] pp1 = Circle.intersect(c1, c2);
		for(Point pp:pp1) {
			Point3D p1=new Point3D(pp.getX(),l1.getY(), pp.getY());
			toLngLat(p1);
		}
	}


}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics