111 lines
4.1 KiB
C#
111 lines
4.1 KiB
C#
using System;
|
||
using System.Threading.Tasks;
|
||
using ThreatSource.Simulation;
|
||
using ThreatSource.Guidance;
|
||
using ThreatSource.Sensor;
|
||
|
||
namespace ThreatSource.Examples
|
||
{
|
||
/// <summary>
|
||
/// 红外成像制导导弹仿真示例
|
||
/// 本示例展示了如何:
|
||
/// 1. 创建和配置一个红外成像制导导弹
|
||
/// 2. 设置仿真环境和参数
|
||
/// 3. 运行仿真并获取结果
|
||
/// </summary>
|
||
public class IRMissileSimulationExample
|
||
{
|
||
private TestSimulationAdapter _adapter;
|
||
private SimulationEntity _missile;
|
||
private SimulationEntity _target;
|
||
private InfraredImagingGuidanceSystem _guidanceSystem;
|
||
|
||
public async Task RunSimulationExample()
|
||
{
|
||
try
|
||
{
|
||
// 步骤1:创建导弹实体
|
||
_missile = new SimulationEntity
|
||
{
|
||
Id = "missile_001",
|
||
Position = new Vector3(0, 0, 0),
|
||
Velocity = new Vector3(0, 0, 0),
|
||
Mass = 100.0f // kg
|
||
};
|
||
|
||
// 步骤2:配置红外成像制导系统
|
||
_guidanceSystem = new InfraredImagingGuidanceSystem
|
||
{
|
||
FieldOfView = 60.0f, // 视场角(度)
|
||
TrackingRange = 20000.0f, // 最大跟踪距离(米)
|
||
UpdateRate = 50 // 制导更新频率(Hz)
|
||
};
|
||
|
||
_missile.GuidanceSystem = _guidanceSystem;
|
||
|
||
// 步骤3:设置目标
|
||
_target = new SimulationEntity
|
||
{
|
||
Id = "target_001",
|
||
Position = new Vector3(10000.0f, 1000.0f, 1000.0f), // 目标在10km外
|
||
Velocity = new Vector3(-100.0f, 0.0f, 0.0f), // 目标以100m/s速度移动
|
||
Signature = new InfraredSignature
|
||
{
|
||
Temperature = 400.0f, // 目标温度(开尔文)
|
||
EmissivityFactor = 0.8f
|
||
}
|
||
};
|
||
|
||
// 步骤4:配置仿真参数
|
||
var config = new SimulationConfig
|
||
{
|
||
TimeStep = 0.02f, // 仿真步长(秒)
|
||
MaxSimulationTime = 60.0f, // 最大仿真时间(秒)
|
||
EnvironmentConditions = new EnvironmentConditions
|
||
{
|
||
Temperature = 288.15f, // 环境温度(开尔文)
|
||
Pressure = 101325.0f, // 大气压力(帕)
|
||
Humidity = 0.5f // 相对湿度
|
||
}
|
||
};
|
||
|
||
// 步骤5:创建仿真适配器并注册事件
|
||
_adapter = new TestSimulationAdapter();
|
||
_adapter.EntityUpdated += OnEntityUpdated;
|
||
_adapter.GuidanceUpdate += OnGuidanceUpdate;
|
||
|
||
// 步骤6:初始化仿真
|
||
await _adapter.Initialize(config);
|
||
await _adapter.AddEntity(_missile);
|
||
await _adapter.AddEntity(_target);
|
||
|
||
// 步骤7:启动仿真
|
||
await _adapter.StartSimulation();
|
||
|
||
// 步骤8:等待仿真结束
|
||
while (_adapter.IsRunning)
|
||
{
|
||
await Task.Delay(100);
|
||
}
|
||
|
||
// 步骤9:获取仿真结果
|
||
var results = await _adapter.GetSimulationResults();
|
||
Console.WriteLine($"仿真结束,命中精度: {results.MissDistance:F2}米");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"仿真过程出错: {ex.Message}");
|
||
}
|
||
}
|
||
|
||
private void OnEntityUpdated(SimulationEntity entity)
|
||
{
|
||
Console.WriteLine($"实体 {entity.Id} 位置更新: ({entity.Position.X:F2}, {entity.Position.Y:F2}, {entity.Position.Z:F2})");
|
||
}
|
||
|
||
private void OnGuidanceUpdate(GuidanceInfo info)
|
||
{
|
||
Console.WriteLine($"制导更新: 距离目标 {info.DistanceToTarget:F2}米");
|
||
}
|
||
}
|
||
} |