aijinhui
2024-01-14 e9582af916d019c4695b0aaf9665039be1bd6ea1
ard-work/src/main/java/com/ruoyi/utils/tube/TubeTools.java
@@ -1,7 +1,11 @@
package com.ruoyi.utils.tube;
import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Comparator;
@@ -20,22 +24,22 @@
public class TubeTools {
    public static void main(String[] args) {
        // 假设给定的三个坐标点 A、B、C
        double x1 = 124.939903268;
        double y1 = 46.684520056;
        double x2 = 124.94049634327537;
        double y2 = 46.68442539350505;
        double x3 = 124.940552075;
        double y3 = 46.684416498;
        GeoPoint pointA = new GeoPoint(124.939903268, 46.684520056, 143.3 - 0.73);
        GeoPoint pointB = new GeoPoint(124.94034787826001, 46.68444909044429, 144.12232823014708);
        GeoPoint pointC = new GeoPoint(124.940552075, 46.684416498, 144.5 - 0.81);
        double distance = getDistance(x1, y1, x3, y3);
        log.debug("总距离:" + distance);
        double distance1 = getDistance(x1, y1, x2, y2);
        log.debug("距离起点距离:" + distance1);
        double distance2 = getDistance(x2, y2, x3, y3);
        log.debug("距离终点距离:" + distance2);
        double distance = getDistance(pointA, pointC);
        double diffAC = pointA.getAltitude() - pointC.getAltitude();
        log.info("AC总距离:" + distance + " AC高度差:" + diffAC);
        double distance1 = getDistance(pointA, pointB);
        double diffAB = pointA.getAltitude() - pointB.getAltitude();
        log.info("AB距离:" + distance1 + " AB高度差:" + diffAB);
        double distance2 = getDistance(pointB, pointC);
        double diffBC = pointB.getAltitude() - pointC.getAltitude();
        log.info("BC距离:" + distance2 + " BC高度差:" + diffBC);
        // 计算斜率
        double slope1 = (y2 - y1) / (x2 - x1);
        double slope2 = (y3 - y2) / (x3 - x2);
        double slope1 = (pointB.getLatitude() - pointA.getLatitude()) / (pointB.getLongitude() - pointA.getLongitude());
        double slope2 = (pointC.getLatitude() - pointB.getLatitude()) / (pointC.getLongitude() - pointB.getLongitude());
        // 设置斜率差值的阈值
        double threshold = 0.000001;
@@ -49,29 +53,30 @@
    }
    /**
     * @描述 计算坐标
     * @参数 [ardTubesDetails, alarmPointDistance]
     * @返回值 void
     * @创建人 刘苏义
     * @创建时间 2023/6/8 14:38
     * @修改人和其它信息
     *  计算坐标
     *
     *  刘苏义
     *  2023/6/8 14:38
     */
    public static GeoPoint CalculateCoordinates(List<ArdTubesDetails> ardTubesDetails, Integer alarmPointDistance) {
            try {
                if(StringUtils.isNull(alarmPointDistance))
                {
                    log.debug("报警点距离为空,无法计算坐标");
                    return null;
                }
                Comparator<ArdTubesDetails> comparator = Comparator.comparingInt(person -> Integer.parseInt(person.getInflectionPointNumber())); // 使用Collections.sort方法进行排序
                Collections.sort(ardTubesDetails, comparator);
                double x = ardTubesDetails.get(0).getLongitude();
                double y = ardTubesDetails.get(0).getLatitude();
                GeoPoint point0 = new GeoPoint(ardTubesDetails.get(0).getLongitude(), ardTubesDetails.get(0).getLatitude(), ardTubesDetails.get(0).getAltitude() - ardTubesDetails.get(0).getDepth());
                TreeMap<Integer, Double> distanceMap = new TreeMap<>();
                TreeMap<Integer, Object> tubeMap = new TreeMap<>();
                double distance = 0.0;
                for (ArdTubesDetails atd : ardTubesDetails) {
                    distance += getDistance(x, y, atd.getLongitude(), atd.getLatitude());
                    GeoPoint point = new GeoPoint(atd.getLongitude(), atd.getLatitude(), atd.getAltitude() - atd.getDepth());
                    distance += getDistance(point, point0);
                    distanceMap.put(Integer.parseInt(atd.getInflectionPointNumber()), distance);
                    tubeMap.put(Integer.parseInt(atd.getInflectionPointNumber()), atd);
                    x = atd.getLongitude();
                    y = atd.getLatitude();
                    point0 = point;
                }
                Integer num = 0;
                double tempDistance = 0.0;
@@ -184,35 +189,19 @@
        return angle;
    }
    private static final double EARTH_RADIUS = 6378.137; // 6378.137为地球半径(单位:千米)
    /**
     * 根据经纬度,计算两点间的距离
     *
     * @param longitude1 第一个点的经度
     * @param latitude1  第一个点的纬度
     * @param longitude2 第二个点的经度
     * @param latitude2  第二个点的纬度
     * @return 返回距离 单位千米
     * @param GeoPoint pa 第一个点
     * @param GeoPoint  pb 第二个点
     * @return 返回距离 单位米
     */
    private static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
        // 纬度
        double lat1 = Math.toRadians(latitude1);
        double lat2 = Math.toRadians(latitude2);
        // 经度
        double lng1 = Math.toRadians(longitude1);
        double lng2 = Math.toRadians(longitude2);
        // 纬度之差
        double a = lat1 - lat2;
        // 经度之差
        double b = lng1 - lng2;
        // 计算两点距离的公式
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
                Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
        // 弧长乘地球半径, 返回单位: 千米
        s = s * EARTH_RADIUS;
        //System.out.println("距离"+s);
        return s * 1000;
    public static GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
    public static double getDistance(GeoPoint pa, GeoPoint pb) {
        GlobalCoordinates source = new GlobalCoordinates(pa.getLatitude(), pa.getLongitude());
        GlobalCoordinates target = new GlobalCoordinates(pb.getLatitude(), pb.getLongitude());
        double distance = geodeticCalculator.calculateGeodeticCurve(Ellipsoid.WGS84, source, target).getEllipsoidalDistance();
        double res = Math.sqrt(Math.pow(pa.getAltitude() - pb.getAltitude(), 2) + Math.pow(distance, 2));
        return res;
    }
}