package com.ruoyi.alarm.tubeAlarm.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class LeakPointCalculation {
|
public static void main(String[] args) {
|
// 假设有三段管线
|
List<Point3D> pipeline = new ArrayList<>();
|
pipeline.add(new Point3D(124.925198285, 46.68693001, 147.5)); // 第一段管线的起点坐标
|
pipeline.add(new Point3D(124.925490653, 46.687071291, 148.2)); // 第一段管线的终点坐标和高程
|
pipeline.add(new Point3D(124.926401943, 46.686812672, 143.5)); // 第二段管线的终点坐标和高程
|
pipeline.add(new Point3D(124.926981879, 46.686644854, 147.4)); // 第三段管线的终点坐标和高程
|
|
double leakPointDistance = 100.0; // 泄漏点相对于管线起点的长度
|
|
// 1. 确定泄漏点所在的管线段
|
Point3D startPoint = null;
|
Point3D endPoint = null;
|
double accumulatedLength = 0.0;
|
for (int i = 0; i < pipeline.size() - 1; i++) {
|
startPoint = pipeline.get(i);
|
endPoint = pipeline.get(i + 1);
|
double segmentLength = calculateDistance(startPoint, endPoint);
|
accumulatedLength += segmentLength;
|
if (accumulatedLength >= leakPointDistance) {
|
break;
|
}
|
}
|
|
// 2. 计算泄漏点在所在管线段上的相对位置
|
double relativePosition = (accumulatedLength - leakPointDistance) / calculateDistance(startPoint, endPoint);
|
|
// 3. 计算泄漏点的坐标
|
double x = startPoint.getX() + (endPoint.getX() - startPoint.getX()) * relativePosition;
|
double y = startPoint.getY() + (endPoint.getY() - startPoint.getY()) * relativePosition;
|
double z = startPoint.getZ() + (endPoint.getZ() - startPoint.getZ()) * relativePosition;
|
|
Point3D leakPoint = new Point3D(x, y, z);
|
System.out.println("泄漏点坐标:" + leakPoint);
|
}
|
|
// 计算两个点之间的距离
|
private static double calculateDistance(Point3D point1, Point3D point2) {
|
double dx = point2.getX() - point1.getX();
|
double dy = point2.getY() - point1.getY();
|
double dz = point2.getZ() - point1.getZ();
|
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
}
|
}
|