|
@@ -10,25 +10,27 @@ import java.io.*;
|
|
|
|
|
|
|
|
|
public class GisCoordinateUtil {
|
|
|
- private static double dx;//x方向增量
|
|
|
- private static double dy;//y方向增量
|
|
|
- private static double locationplaneVector[];//本地向量
|
|
|
- private static double geographicplaneVector[];//地理平面坐标系向量
|
|
|
- private static double centerLon;//中央经度
|
|
|
+ private static double dx;//x方向增量
|
|
|
+ private static double dy;//y方向增量
|
|
|
+ private static double locationplaneVector[];//本地向量
|
|
|
+ private static double geographicplaneVector[];//地理平面坐标系向量
|
|
|
+ private static double centerLon;//中央经度
|
|
|
|
|
|
|
|
|
private final static String coordCode4326 = "EPSG:4326";
|
|
|
private final static String coordCode3857 = "EPSG:3857";
|
|
|
+
|
|
|
/**
|
|
|
* 解析控制点文件
|
|
|
- * @param controlPointsFileUrl 控制点文件路径
|
|
|
+ *
|
|
|
+ * @param controlPointsFileUrl 控制点文件路径
|
|
|
*/
|
|
|
- public static void parseControlPointsFile (String controlPointsFileUrl){
|
|
|
+ public static void parseControlPointsFile(String controlPointsFileUrl) {
|
|
|
String jsonStr = "";
|
|
|
try {
|
|
|
File file = new File(controlPointsFileUrl);
|
|
|
FileReader fileReader = new FileReader(file);
|
|
|
- Reader reader = new InputStreamReader(new FileInputStream(file),"Utf-8");
|
|
|
+ Reader reader = new InputStreamReader(new FileInputStream(file), "Utf-8");
|
|
|
int ch = 0;
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
while ((ch = reader.read()) != -1) {
|
|
@@ -45,33 +47,35 @@ public class GisCoordinateUtil {
|
|
|
|
|
|
/**
|
|
|
* 解析json字符串
|
|
|
+ *
|
|
|
* @param jsonStr
|
|
|
*/
|
|
|
- private static void parseJSON(String jsonStr){
|
|
|
+ private static void parseJSON(String jsonStr) {
|
|
|
// JSONObject json= JSONObject.fromObject(jsonStr);
|
|
|
JSONObject json = JSONObject.parseObject(jsonStr);
|
|
|
- JSONArray points=json.getJSONArray("points");
|
|
|
- JSONObject aPoint=(JSONObject)points.get(0);
|
|
|
- JSONObject bPoint=(JSONObject)points.get(1);
|
|
|
- JSONObject aPointCoordinate=(JSONObject)aPoint.get("coordinate");
|
|
|
- JSONObject aPointLocation=(JSONObject)aPoint.get("location");
|
|
|
- JSONObject bPointCoordinate=(JSONObject)bPoint.get("coordinate");
|
|
|
- JSONObject bPointLocation=(JSONObject)bPoint.get("location");
|
|
|
- double alon=aPointCoordinate.getDouble("longitude");
|
|
|
- double alat=aPointCoordinate.getDouble("latitude");
|
|
|
- double aX=aPointLocation.getDouble("x");
|
|
|
- double aY=aPointLocation.getDouble("y");
|
|
|
- double blon=bPointCoordinate.getDouble("longitude");
|
|
|
- double blat=bPointCoordinate.getDouble("latitude");
|
|
|
- double bX=bPointLocation.getDouble("x");
|
|
|
- double bY=bPointLocation.getDouble("y");
|
|
|
- calculateVariable (alon,alat,aX,aY,blon,blat,bX,bY);
|
|
|
- // System.out.println(alon+" "+alat+" "+aX+" "+aY+" "+blon+" "+blat+" "+bX+" "+bY);
|
|
|
+ JSONArray points = json.getJSONArray("points");
|
|
|
+ JSONObject aPoint = (JSONObject) points.get(0);
|
|
|
+ JSONObject bPoint = (JSONObject) points.get(1);
|
|
|
+ JSONObject aPointCoordinate = (JSONObject) aPoint.get("coordinate");
|
|
|
+ JSONObject aPointLocation = (JSONObject) aPoint.get("location");
|
|
|
+ JSONObject bPointCoordinate = (JSONObject) bPoint.get("coordinate");
|
|
|
+ JSONObject bPointLocation = (JSONObject) bPoint.get("location");
|
|
|
+ double alon = aPointCoordinate.getDouble("longitude");
|
|
|
+ double alat = aPointCoordinate.getDouble("latitude");
|
|
|
+ double aX = aPointLocation.getDouble("x");
|
|
|
+ double aY = aPointLocation.getDouble("y");
|
|
|
+ double blon = bPointCoordinate.getDouble("longitude");
|
|
|
+ double blat = bPointCoordinate.getDouble("latitude");
|
|
|
+ double bX = bPointLocation.getDouble("x");
|
|
|
+ double bY = bPointLocation.getDouble("y");
|
|
|
+ calculateVariable(alon, alat, aX, aY, blon, blat, bX, bY);
|
|
|
+ // System.out.println(alon+" "+alat+" "+aX+" "+aY+" "+blon+" "+blat+" "+bX+" "+bY);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 控制点
|
|
|
* 根据两个控制点计算增量及用于计算角度的两个向量
|
|
|
+ *
|
|
|
* @param alon
|
|
|
* @param alat
|
|
|
* @param aX
|
|
@@ -81,148 +85,312 @@ public class GisCoordinateUtil {
|
|
|
* @param bX
|
|
|
* @param bY
|
|
|
*/
|
|
|
- public static void calculateVariable (double alon,double alat,double aX,double aY,double blon,double blat,double bX,double bY){
|
|
|
-
|
|
|
- double[] a= GisCoordinateTransform.convert2000BLToGauss(alon,alat);
|
|
|
- double[] b= GisCoordinateTransform.convert2000BLToGauss(blon,blat);
|
|
|
-
|
|
|
- dx=a[0]-aX;
|
|
|
- dy=a[1]-aY;
|
|
|
- locationplaneVector=new double[2];
|
|
|
- locationplaneVector[0]=a[0]-b[0];
|
|
|
- locationplaneVector[1]=a[1]-b[1];
|
|
|
- geographicplaneVector=new double[2];
|
|
|
- geographicplaneVector[0]=aX-bX;
|
|
|
- geographicplaneVector[1]=aY-bY;
|
|
|
- centerLon=GisCoordinateTransform.getZone3CenterLon(alon);
|
|
|
+ public static void calculateVariable(double alon, double alat, double aX, double aY, double blon, double blat, double bX, double bY) {
|
|
|
+
|
|
|
+ double[] a = GisCoordinateTransform.convert2000BLToGauss(alon, alat);
|
|
|
+ double[] b = GisCoordinateTransform.convert2000BLToGauss(blon, blat);
|
|
|
+
|
|
|
+ dx = a[0] - aX;
|
|
|
+ dy = a[1] - aY;
|
|
|
+ locationplaneVector = new double[2];
|
|
|
+ locationplaneVector[0] = a[0] - b[0];
|
|
|
+ locationplaneVector[1] = a[1] - b[1];
|
|
|
+ geographicplaneVector = new double[2];
|
|
|
+ geographicplaneVector[0] = aX - bX;
|
|
|
+ geographicplaneVector[1] = aY - bY;
|
|
|
+ centerLon = GisCoordinateTransform.getZone3CenterLon(alon);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 本地坐标转经纬度
|
|
|
+ *
|
|
|
* @param loctionX
|
|
|
* @param loctionY
|
|
|
* @return
|
|
|
*/
|
|
|
- public static double[] transformLocationToBL(double loctionX,double loctionY){
|
|
|
- double x1=locationplaneVector[0];
|
|
|
- double y1=locationplaneVector[1];
|
|
|
- double x2=geographicplaneVector[0];
|
|
|
- double y2=geographicplaneVector[1];
|
|
|
+ public static double[] transformLocationToBL(double loctionX, double loctionY) {
|
|
|
+ double x1 = locationplaneVector[0];
|
|
|
+ double y1 = locationplaneVector[1];
|
|
|
+ double x2 = geographicplaneVector[0];
|
|
|
+ double y2 = geographicplaneVector[1];
|
|
|
// double tana1=y1/x1;
|
|
|
// double tana2=y2/x2;
|
|
|
- double a1=Math.atan2(y1, x1);
|
|
|
- double a2=Math.atan2(y2, x2);
|
|
|
- double a=a2-a1;
|
|
|
- double sinazimuth,cosazimuth;
|
|
|
- cosazimuth=Math.cos(a);
|
|
|
- sinazimuth=Math.sin(a);
|
|
|
- double resultX=loctionY*sinazimuth+loctionX*cosazimuth;
|
|
|
- double resultY=loctionY*cosazimuth-loctionX*sinazimuth;
|
|
|
- double x=resultX+dx;
|
|
|
- double y=resultY+dy;
|
|
|
-
|
|
|
+ double a1 = Math.atan2(y1, x1);
|
|
|
+ double a2 = Math.atan2(y2, x2);
|
|
|
+ double a = a2 - a1;
|
|
|
+ double sinazimuth, cosazimuth;
|
|
|
+ cosazimuth = Math.cos(a);
|
|
|
+ sinazimuth = Math.sin(a);
|
|
|
+ double resultX = loctionY * sinazimuth + loctionX * cosazimuth;
|
|
|
+ double resultY = loctionY * cosazimuth - loctionX * sinazimuth;
|
|
|
+ double x = resultX + dx;
|
|
|
+ double y = resultY + dy;
|
|
|
|
|
|
|
|
|
// return GisCoordinateTransform.Convert2000GaussToBL(x,y,centerLon);
|
|
|
// return GisCoordinateTransform.convertByProj4(x,y, coordCode3857, coordCode4326);
|
|
|
- return GisCoordinateTransform.convert2000GaussToBL(x,y,centerLon);
|
|
|
+ return GisCoordinateTransform.convert2000GaussToBL(x, y, centerLon);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 经纬度转本地坐标
|
|
|
+ *
|
|
|
* @param lon 经度 十进制度
|
|
|
* @param lat 纬度 十进制度
|
|
|
* @return
|
|
|
*/
|
|
|
- public static double[] transformBLToLocation(double lon,double lat){
|
|
|
+ public static double[] transformBLToLocation(double lon, double lat) {
|
|
|
|
|
|
|
|
|
- double[] gauss= GisCoordinateTransform.convert2000BLToGauss(lon,lat);
|
|
|
- double x1=locationplaneVector[0];
|
|
|
- double y1=locationplaneVector[1];
|
|
|
- double x2=geographicplaneVector[0];
|
|
|
- double y2=geographicplaneVector[1];
|
|
|
- double a1=Math.atan2(y1,x1);
|
|
|
- double a2=Math.atan2(y2,x2);
|
|
|
+ double[] gauss = GisCoordinateTransform.convert2000BLToGauss(lon, lat);
|
|
|
+ double x1 = locationplaneVector[0];
|
|
|
+ double y1 = locationplaneVector[1];
|
|
|
+ double x2 = geographicplaneVector[0];
|
|
|
+ double y2 = geographicplaneVector[1];
|
|
|
+ double a1 = Math.atan2(y1, x1);
|
|
|
+ double a2 = Math.atan2(y2, x2);
|
|
|
// double a=a1-a2;
|
|
|
- double a=0;
|
|
|
- double sinazimuth,cosazimuth;
|
|
|
- cosazimuth=Math.cos(a);
|
|
|
- sinazimuth=Math.sin(a);
|
|
|
- double resultX=gauss[1]*sinazimuth+gauss[0]*cosazimuth;
|
|
|
- double resultY=gauss[1]*cosazimuth-gauss[0]*sinazimuth;
|
|
|
- double x=resultX-dx;
|
|
|
- double y=resultY-dy;
|
|
|
- double[] location=new double[2];
|
|
|
- location[0]=x;
|
|
|
- location[1]=y;
|
|
|
+ double a = 0;
|
|
|
+ double sinazimuth, cosazimuth;
|
|
|
+ cosazimuth = Math.cos(a);
|
|
|
+ sinazimuth = Math.sin(a);
|
|
|
+ double resultX = gauss[1] * sinazimuth + gauss[0] * cosazimuth;
|
|
|
+ double resultY = gauss[1] * cosazimuth - gauss[0] * sinazimuth;
|
|
|
+ double x = resultX - dx;
|
|
|
+ double y = resultY - dy;
|
|
|
+ double[] location = new double[2];
|
|
|
+ location[0] = x;
|
|
|
+ location[1] = y;
|
|
|
return location;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 经纬度转本地坐标
|
|
|
+ *
|
|
|
* @param position 经纬度
|
|
|
- * @param dto 控制点
|
|
|
+ * @param dto 控制点
|
|
|
* @return
|
|
|
*/
|
|
|
- public static double[] convertGpsToLocation(double[] position, ControlPointEntity dto ) {
|
|
|
+ public static double[] convertGpsToLocation(double[] position, ControlPointEntity dto) {
|
|
|
double[] controlLocation1 = dto.getAgeControlLocation1();
|
|
|
double[] controlLocation2 = dto.getAgeControlLocation2();
|
|
|
|
|
|
double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
|
|
|
double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
|
|
|
- GisCoordinateUtil.calculateVariable (controlCoordinate1[0],controlCoordinate1[1],controlLocation1[0],controlLocation1[1],controlCoordinate2[0],controlCoordinate2[1],controlLocation2[0],controlLocation2[1]);
|
|
|
+ GisCoordinateUtil.calculateVariable(controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
|
|
|
double[] d = GisCoordinateUtil.transformBLToLocation(position[0], position[1]);
|
|
|
return d;
|
|
|
}
|
|
|
|
|
|
+// /**
|
|
|
+// * 本地坐标转经纬度
|
|
|
+// *
|
|
|
+// * @param position 经纬度
|
|
|
+// * @param dto 控制点
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public static double[] convertLocationToGps(double[] position, ControlPointEntity dto) {
|
|
|
+// double[] controlLocation1 = dto.getAgeControlLocation1();
|
|
|
+// double[] controlLocation2 = dto.getAgeControlLocation2();
|
|
|
+//
|
|
|
+// double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
|
|
|
+// double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
|
|
|
+// GisCoordinateUtil.calculateVariable(controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
|
|
|
+// double[] d = GisCoordinateUtil.transformLocationToBL(position[0], position[1]);
|
|
|
+// return d;
|
|
|
+// }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 两个控制点的纠偏,已知两个控制点的未纠偏前的经纬度和控制点的真实经纬度,求真实位置相对于未纠偏之前的旋转 角度
|
|
|
- * @param relativePoint1 【经度,纬度】 [113,22] ,相对坐标用算法生成的控制点
|
|
|
+ * @param relativePoint1 【经度,纬度】 [113,22] ,页面输入的相对坐标转gis坐标
|
|
|
* @param absolutelyPoint1 【经度,纬度】 [113,22] 绝对坐标:用页面输入的坐标
|
|
|
- * @param relativePoint2 【经度,纬度】 [113,22] ,相对坐标用算法生成的控制点
|
|
|
+ * @param relativePoint2 【经度,纬度】 [113,22] ,页面输入的相对坐标转gis坐标
|
|
|
* @param absolutelyPoint2 【经度,纬度】 [113,22] 绝对坐标:用页面输入的坐标
|
|
|
- * @return 弧度 设置到dataSet.orientation
|
|
|
+ * @return 弧度 设置到dataSet.orientation
|
|
|
*/
|
|
|
- private static double getAngle(double[] relativePoint1,double[] absolutelyPoint1,double[] relativePoint2,double[] absolutelyPoint2){
|
|
|
- double[] relativeVector=new double[2];
|
|
|
- double[] absolutelyVector=new double[2];
|
|
|
- relativeVector[0]=relativePoint2[0]-relativePoint1[0];
|
|
|
- relativeVector[1]=relativePoint2[1]-relativePoint1[1];
|
|
|
- absolutelyVector[0]=absolutelyPoint2[0]-absolutelyPoint1[0];
|
|
|
- absolutelyVector[1]=absolutelyPoint2[1]-absolutelyPoint1[1];
|
|
|
- double a1=Math.atan2(relativeVector[1], relativeVector[0]);
|
|
|
- double a2=Math.atan2(absolutelyVector[1], absolutelyVector[0]);
|
|
|
- return a1-a2;
|
|
|
- }
|
|
|
+// private static double getAngle(double[] relativePoint1,double[] absolutelyPoint1,double[] relativePoint2,double[] absolutelyPoint2){
|
|
|
+// double[] relativeVector=new double[2];
|
|
|
+// double[] absolutelyVector=new double[2];
|
|
|
+// relativeVector[0]=relativePoint2[0]-relativePoint1[0];
|
|
|
+// relativeVector[1]=relativePoint2[1]-relativePoint1[1];
|
|
|
+// absolutelyVector[0]=absolutelyPoint2[0]-absolutelyPoint1[0];
|
|
|
+// absolutelyVector[1]=absolutelyPoint2[1]-absolutelyPoint1[1];
|
|
|
+// double a1=Math.atan2(relativeVector[1], relativeVector[0]);
|
|
|
+// double a2=Math.atan2(absolutelyVector[1], absolutelyVector[0]);
|
|
|
+// return a1-a2;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 获取弧度
|
|
|
+ *
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+// public static double getAngle(ControlPointEntity dto){
|
|
|
+//
|
|
|
+// double[] relativePoint1 = dto.getRelativePoint1();
|
|
|
+// double[] absolutelyPoint1 = dto.getGpsControlCoordinate1();
|
|
|
+// double[] relativePoint2 = dto.getRelativePoint2();
|
|
|
+// double[] absolutelyPoint2 = dto.getGpsControlCoordinate2();
|
|
|
+// return getAngle(relativePoint1, absolutelyPoint1, relativePoint2, absolutelyPoint2);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取弧度, 采用本地坐标
|
|
|
+ *
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
- public static double getAngle(ControlPointEntity dto){
|
|
|
+// public static double getAngleOrientation(ControlPointEntity dto) {
|
|
|
+//
|
|
|
+// //gps转本地坐标
|
|
|
+// double[] defaultP1 = convertGpsToLocation(dto.getGpsControlCoordinate1(), dto);
|
|
|
+// double[] defaultP2 = convertGpsToLocation(dto.getGpsControlCoordinate2(), dto);
|
|
|
+//
|
|
|
+// double[] ageControlLocation1 = dto.getAgeControlLocation1();
|
|
|
+// double[] ageControlLocation2 = dto.getAgeControlLocation2();
|
|
|
+//
|
|
|
+// return getAngle(defaultP1, defaultP2, ageControlLocation1, ageControlLocation2);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+ //采用本地坐标
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取弧度, 采用本地坐标
|
|
|
+ * P1,P2是传过来的本地坐标
|
|
|
+ * defaultP1和defaultP2是传过来的gis坐标通过当前的控制点转换成新的本地坐标
|
|
|
+ *
|
|
|
+ * @param defaultP1
|
|
|
+ * @param defaultP2
|
|
|
+ * @param P1 P1,P2是传过来的本地坐标
|
|
|
+ * @param P2
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+// private static double getAngle(double[] defaultP1, double[] defaultP2, double[] P1, double[] P2) {
|
|
|
+// double dx = P1[0] - defaultP1[0];
|
|
|
+// double dy = P1[1] - defaultP1[1];
|
|
|
+//
|
|
|
+// P2[0] = P2[0] - dx;
|
|
|
+// P2[1] = P2[1] - dy;
|
|
|
+//
|
|
|
+// //p1,p2,defaultP2
|
|
|
+// double angle = Angle(P1, P2, defaultP2);
|
|
|
+// return angle;
|
|
|
+// }
|
|
|
+//
|
|
|
+// private static double Angle(double[] p, double[] p1, double[] p2) {
|
|
|
+// double cosfi = 0, fi = 0, norm = 0;
|
|
|
+// double dsx = p1[0] - p[0];
|
|
|
+// double dsy = p1[1] - p[1];
|
|
|
+// double dex = p2[0] - p[0];
|
|
|
+// double dey = p2[1] - p[1];
|
|
|
+//
|
|
|
+// cosfi = dsx * dex + dsy * dey;
|
|
|
+// norm = (dsx * dsx + dsy * dsy) * (dex * dex + dey * dey);
|
|
|
+// cosfi /= Math.sqrt(norm);
|
|
|
+//
|
|
|
+// if (cosfi >= 1.0) return 0;
|
|
|
+// //if (cosfi <= -1.0) return Math.PI;
|
|
|
+// if (cosfi <= -1.0) return 180;
|
|
|
+// fi = Math.acos(cosfi);
|
|
|
+//
|
|
|
+// if (180 * fi / Math.PI < 180) {
|
|
|
+// return fi;
|
|
|
+// } else {
|
|
|
+// return 2 * Math.PI - fi;
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 采用本地坐标
|
|
|
+ * 获取dataSet.orientation:弧度
|
|
|
+ * @param dto 控制点
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static double getDataSetOrientation(ControlPointEntity dto) {
|
|
|
+
|
|
|
+ //web输入控制点的gis坐标
|
|
|
+ double[] webGisP1 = dto.getGpsControlCoordinate1();
|
|
|
+ double[] webGisP2 = dto.getGpsControlCoordinate2();
|
|
|
|
|
|
- double[] relativePoint1 = dto.getRelativePoint1();
|
|
|
- double[] absolutelyPoint1 = dto.getGpsControlCoordinate1();
|
|
|
- double[] relativePoint2 = dto.getRelativePoint2();
|
|
|
- double[] absolutelyPoint2 = dto.getGpsControlCoordinate2();
|
|
|
- return getAngle(relativePoint1, absolutelyPoint1, relativePoint2, absolutelyPoint2);
|
|
|
+
|
|
|
+ // 将算法部提供控制点赋值,用于计算
|
|
|
+ dto.setGpsControlCoordinate1(dto.getDefaultGisP1());
|
|
|
+ dto.setGpsControlCoordinate2(dto.getDefaultGisP2());
|
|
|
+ dto.setAgeControlLocation1(dto.getDefaultLocation1());
|
|
|
+ dto.setAgeControlLocation2(dto.getDefaultLocation2());
|
|
|
+ // defaultP1,defaultP2使用的是算法部提供的控制点得出结果, 人工输入gis坐标转 本地坐标
|
|
|
+ double[] defaultP1 = convertGpsToLocation(webGisP1, dto);
|
|
|
+ double[] defaultP2 = convertGpsToLocation(webGisP2, dto);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // web输入控制点的本地坐标
|
|
|
+ double[] ageControlLocation1 = dto.getAgeControlLocation1();
|
|
|
+ double[] ageControlLocation2 = dto.getAgeControlLocation2();
|
|
|
+
|
|
|
+ return getOrientation(defaultP1, defaultP2, ageControlLocation1, ageControlLocation2);
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void testGetAngle(){
|
|
|
- double[] relativePoint1 = { 113.595725873337, 22.366579193007};
|
|
|
- double[] absolutelyPoint1 = {113.595725873337, 22.366579193007};
|
|
|
- double[] relativePoint2 = {113.595754224886, 22.3665878935361};
|
|
|
- double[] absolutelyPoint2 = {113.595754224886, 22.3665878935361};
|
|
|
- double angle = getAngle(relativePoint1, absolutelyPoint1, relativePoint2, absolutelyPoint2);
|
|
|
- System.out.println(angle);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2021-09-07
|
|
|
+ * 采用本地坐标
|
|
|
+ * P1和P2是人工输入的本地坐标
|
|
|
+ * defaultP1和defaultP2是采用算法部给的控制点将人工输入的gis坐标转换成本地坐标
|
|
|
+ * 这四个参数:defaultP1和defaultP2(来自人工输入的gis坐标,再通过默认控制点转换成本地坐标),P1和P2(人工输入的本地坐标)
|
|
|
+ * @param defaultP1
|
|
|
+ * @param defaultP2
|
|
|
+ * @param P1
|
|
|
+ * @param P2
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static double getOrientation(double[] defaultP1,double[] defaultP2,double[] P1,double[] P2){
|
|
|
+
|
|
|
+
|
|
|
+ double dx1 = defaultP2[0] - defaultP1[0];
|
|
|
+ double dy1 = defaultP2[1] - defaultP1[1];
|
|
|
+ double dz1 = 0;
|
|
|
+
|
|
|
+ double dx2 = P2[0] - P1[0];
|
|
|
+ double dy2 = P2[1] - P1[1];
|
|
|
+ double dz2 = 0;
|
|
|
+
|
|
|
+ double lengthSq1 = dx1*dx1 + dy1*dy1;
|
|
|
+ double lengthSq2 = dx2*dx2 + dy2*dy2;
|
|
|
+
|
|
|
+ double denominator = Math.sqrt( lengthSq1 * lengthSq2 );
|
|
|
+
|
|
|
+ double angle = 0;
|
|
|
+ if ( denominator == 0 ) {
|
|
|
+ angle = Math.PI / 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ double theta = (dx1*dx2+dy1*dy2) / denominator;
|
|
|
+
|
|
|
+ //angle = Math.acos( MathUtils.clamp( theta, - 1, 1 ) );
|
|
|
+ angle = Math.acos( Math.max(- 1, Math.min(theta, 1)) );
|
|
|
+ //if(vec1.clone().cross(vec2).z < 0)angle *= -1 //这里不确定是<0还是>0
|
|
|
+ double ax = dx1;
|
|
|
+ double ay = dy1;
|
|
|
+ if((dx1*dy2-dy1*dx2)<0) {
|
|
|
+ angle *= -1;
|
|
|
+ }
|
|
|
+ return angle;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|