修复斜线优化有高度差的路径点的问题。

This commit is contained in:
tian 2025-10-12 01:12:31 +08:00
parent 37f03362c4
commit 455450726c

View File

@ -1579,13 +1579,38 @@ namespace NavisworksTransport.PathPlanning
var distance = Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) +
Math.Pow(endPoint.Y - startPoint.Y, 2));
// 🔥 关键修复:检查起点和终点的高度差,如果超过阈值就不能跳过
// 这样可以防止从地面直接跳到楼梯上层
double totalHeightDiff = Math.Abs(endPoint.Z - startPoint.Z);
const double maxAllowedHeightDiffMeters = 0.3; // 0.3米,允许小台阶但不允许跨越整个楼梯
// 🔥 修复:检查高度变化,有高度变化就不能优化掉
// 1. 起终点高度差不能超过阈值(原有逻辑:防止跨越大高度差,例如楼梯)
// 2. 中间点高度必须与起点和终点一致(新增逻辑:任何高度变化都不能优化掉)
bool canSkip = false;
double maxAllowedHeightDiffMeters = GetMaxHeightDiffMeters(); // 从配置文件读取高度差阈值
double maxAllowedHeightDiffInModelUnits = maxAllowedHeightDiffMeters * UnitsConverter.GetMetersToUnitsConversionFactor();
bool canSkip = totalHeightDiff <= maxAllowedHeightDiffInModelUnits;
double startZ = startPoint.Z;
double endZ = endPoint.Z;
double totalHeightDiff = Math.Abs(endZ - startZ);
// 检查1起终点高度差必须在阈值内
if (totalHeightDiff <= maxAllowedHeightDiffInModelUnits)
{
// 检查2所有中间点的高度必须与起点和终点一致不能有高度变化
bool hasMiddleHeightChange = false;
const double heightTolerance = 1e-6; // 浮点精度容差
for (int midIndex = currentIndex + 1; midIndex < testIndex; midIndex++)
{
double midZ = optimizedPath[midIndex].Z;
// 如果中间点高度与起点或终点不同,说明有高度变化,不能优化掉
if (Math.Abs(midZ - startZ) > heightTolerance ||
Math.Abs(midZ - endZ) > heightTolerance)
{
hasMiddleHeightChange = true;
break;
}
}
canSkip = !hasMiddleHeightChange;
}
if (canSkip && IsDirectPathClear(startPoint, endPoint, gridMap))
{