You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project/Src/command_center/web-command-center/test/test-astar-debug.js

115 lines
3.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 测试A*算法的威胁区域避让功能
// 手动导入路径规划模块
const pathPlanningModule = require('./backend/src/routes/pathPlanning.js');
// 从用户日志中提取的实际测试数据
const testData = {
"startPoint": {
"lng": 112.969693,
"lat": 28.122363
},
"targetPoints": [
{
"lng": 113.031207,
"lat": 28.067036
}
],
"threatZones": [
{
"id": 7,
"type": "radar",
"level": "high",
"geometry_type": "polygon",
"geometry_data": {
"type": "polygon",
"path": [
[112.998212, 28.105175],
[113.053664, 28.111999],
[113.048066, 28.08616],
[112.979811, 28.083835],
[112.968328, 28.097401]
]
},
"description": "2"
},
{
"id": 6,
"type": "aircraft",
"level": "medium",
"geometry_type": "circle",
"geometry_data": {
"type": "circle",
"center": [113.019349, 28.153602],
"radius": 3790.243
},
"description": "1"
}
]
};
async function testAStarWithThreats() {
console.log('=== 测试A*算法威胁区域避让 ===\n');
const startPoint = {
lng: testData.startPoint.lng,
lat: testData.startPoint.lat,
altitude: 100
};
const targetPoint = {
lng: testData.targetPoints[0].lng,
lat: testData.targetPoints[0].lat,
altitude: 100
};
console.log('起点:', startPoint);
console.log('目标点:', targetPoint);
console.log('威胁区数量:', testData.threatZones.length);
// 测试是否起点或目标点在威胁区内
const startThreat = pathPlanningModule.isPointInAnyThreatZone(startPoint.lng, startPoint.lat, testData.threatZones);
const targetThreat = pathPlanningModule.isPointInAnyThreatZone(targetPoint.lng, targetPoint.lat, testData.threatZones);
console.log('起点威胁状态:', startThreat.inThreat ? `在威胁区${startThreat.zoneId}` : '安全');
console.log('目标点威胁状态:', targetThreat.inThreat ? `在威胁区${targetThreat.zoneId}` : '安全');
// 测试直线路径是否经过威胁区
console.log('\n=== 检查直线路径是否经过威胁区 ===');
const directPathPoints = generateDirectPathPoints(startPoint, targetPoint, 20);
let threatPoints = 0;
let threatZonesFound = new Set();
directPathPoints.forEach((point, index) => {
const threat = pathPlanningModule.isPointInAnyThreatZone(point.lng, point.lat, testData.threatZones);
if (threat.inThreat) {
threatPoints++;
threatZonesFound.add(threat.zoneId);
console.log(`${index}: (${point.lng.toFixed(6)}, ${point.lat.toFixed(6)}) - 在威胁区${threat.zoneId}`);
}
});
console.log(`直线路径中的威胁点数: ${threatPoints}/${directPathPoints.length}`);
console.log(`涉及的威胁区: ${Array.from(threatZonesFound).join(', ')}`);
if (threatPoints > 0) {
console.log('✓ 直线路径确实经过威胁区A*算法应该避开');
} else {
console.log('✗ 直线路径不经过威胁区,可能是测试数据有问题');
}
}
// 生成直线路径上的采样点
function generateDirectPathPoints(start, end, numPoints) {
const points = [];
for (let i = 0; i <= numPoints; i++) {
const t = i / numPoints;
const lng = start.lng + t * (end.lng - start.lng);
const lat = start.lat + t * (end.lat - start.lat);
points.push({ lng, lat });
}
return points;
}
// 运行测试
testAStarWithThreats().catch(console.error);