围栏锚点之间按照固定距离补点

这里写自定义目录标题

围栏锚点之间按照固定距离补点

package com.ruoyi.system.utils;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.domain.TbRail;
import com.ruoyi.system.domain.TbRailPoint;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;

import java.awt.geom.Point2D;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
public class RailUtil {


    /**
     * 补点
     * @param start
     * @param end
     * @param distance
     * @return
     */
    public static List<TbRailPoint> interpolatePoints(TbRailPoint start, TbRailPoint end, double distance) {
        List<Point2D.Double> doubleList = interpolatePoints(new Point2D.Double(start.getLongitude().doubleValue(), start.getLatitude().doubleValue())
                , new Point2D.Double(end.getLongitude().doubleValue(), end.getLatitude().doubleValue()),
                distance);
        int sort = Optional.ofNullable(start.getSort()).orElse(0L).intValue();
        List<TbRailPoint> rtn = new ArrayList<>();
        for (Point2D.Double p : doubleList) {
            TbRailPoint tmp = new TbRailPoint();
            tmp.setLongitude(BigDecimal.valueOf(p.x));
            tmp.setLatitude(BigDecimal.valueOf(p.y));
            tmp.setSort(Convert.toLong(++sort));
            rtn.add(tmp);
        }
        return rtn;
    }


    /**
     * 补点原始算法
     * @param start
     * @param end
     * @param distance
     * @return
     */
    private static List<Point2D.Double> interpolatePoints(Point2D.Double start, Point2D.Double end, double distance) {
        List<Point2D.Double> interpolatedPoints = new ArrayList<>();

        // 计算两点之间的距离
        double dx = end.x - start.x;
        double dy = end.y - start.y;
        double totalDistance = Math.sqrt(dx * dx + dy * dy);
        log.info("【3D围栏维护】保存3D围栏,两点之间补偿点,两点间距离 {} ", totalDistance);
        if (totalDistance<distance){
            // 小于补点距离不需要补点
            return interpolatedPoints;
        }

        // 计算需要插值的点数
        int numPoints = (int) (totalDistance / distance);

        // 计算每个插值点的增量
        double incrementX = dx / numPoints;
        double incrementY = dy / numPoints;

        // 迭代插值
        double x = start.x;
        double y = start.y;
        for (int i = 0; i < numPoints; i++) {
            interpolatedPoints.add(new Point2D.Double(x, y));
            x += incrementX;
            y += incrementY;
        }
        interpolatedPoints = interpolatedPoints.subList(1, interpolatedPoints.size());
        return interpolatedPoints;
    }


    

    public static void main(String[] args) {
        // 定义两个经纬度点
        Point2D.Double startPoint = new Point2D.Double(-74.006, 40.7128);
        Point2D.Double endPoint = new Point2D.Double(-73.935242, 40.73061);

        // 定义固定距离(单位:度)
        double fixedDistance = 0.01; // 10km

        // 补点
        List<Point2D.Double> interpolatedPoints = interpolatePoints(startPoint, endPoint, fixedDistance);

        // 输出结果
        System.out.println("Interpolated Points:");
        for (Point2D.Double point : interpolatedPoints) {
            System.out.println(point.x + ", " + point.y);
        }

        
        
    }
}

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值