From f60b7697fea1057c64484ffbfd991bca22b1fd37 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Wed, 30 Oct 2024 14:51:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=AF=BC=E5=BC=B9=E5=92=8C=E5=9D=A6?= =?UTF-8?q?=E5=85=8B=E7=9A=84=E5=B1=9E=E6=80=A7=E5=8D=95=E7=8B=AC=E5=BB=BA?= =?UTF-8?q?=E7=B1=BB=EF=BC=9B=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=AF=BC=E5=BC=B9?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E6=A6=82=E7=8E=87=EF=BC=8C=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E6=A6=82=E7=8E=87=E7=9A=84=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 36 ++- src/Models/Equipment/Tank.cs | 47 +--- src/Models/Equipment/TankProperties.cs | 102 +++++++ .../Guidance/InfraredImagingGuidanceSystem.cs | 5 +- .../Guidance/MillimeterWaveGuidanceSystem.cs | 2 +- .../MIssile/InfraredCommandGuidedMissile.cs | 5 +- .../InfraredImagingTerminalGuidedMissile.cs | 6 +- src/Models/MIssile/LaserBeamRiderMissile.cs | 5 +- .../MIssile/LaserSemiActiveGuidedMissile.cs | 5 +- .../MillimeterWaveTerminalGuidedMissile.cs | 10 +- src/Models/MIssile/MissileBase.cs | 162 +++-------- src/Models/MIssile/MissileProperties.cs | 147 ++++++++++ .../MIssile/TerminalSensitiveMissile.cs | 42 ++- .../MIssile/TerminalSensitiveSubmunition.cs | 13 +- src/Models/Sensor/MillimeterWaveRadiometer.cs | 13 +- src/Simulation/SimulationConfig.cs | 266 +----------------- src/Simulation/SimulationElement.cs | 7 + src/Simulation/SimulationManager.cs | 33 ++- src/Utility/MotionAlgorithm.cs | 36 +++ 19 files changed, 433 insertions(+), 509 deletions(-) create mode 100644 src/Models/Equipment/TankProperties.cs create mode 100644 src/Models/MIssile/MissileProperties.cs diff --git a/Program.cs b/Program.cs index 5a9853c..91e60a9 100644 --- a/Program.cs +++ b/Program.cs @@ -26,7 +26,7 @@ namespace ActiveProtect var config = new SimulationConfig { // 配置坦克 - TankConfigs = new List + TankConfigs = new List { new(tankinfo) { @@ -73,52 +73,54 @@ namespace ActiveProtect ControlFieldDiameter = 6 }, // 配置导弹 - MissileConfigs = new List + MissileConfigs = new List { // 激光半主动制导导弹配置 new() { Id = "LSGM_1", + TargetId = "Tank_1", InitialPosition = new Vector3D(2000, 100, 100), InitialOrientation = new Orientation(Math.PI, -0.1, 0), InitialSpeed = 700, MaxSpeed = 800, - TargetIndex = 0, MaxFlightTime = 10, MaxFlightDistance = 5000, LaunchAcceleration = 50, MaxEngineBurnTime = 10, MaxAcceleration = 400, ProportionalNavigationCoefficient = 4, - ExplosionRadius = 10, + ExplosionRadius = 5, + HitProbability = 0.9, Mass = 50, Type = MissileType.LaserSemiActiveGuidance }, // 激光驾束制导导弹配置 new() { Id = "LBRM_1", + TargetId = "Tank_1", InitialPosition = new Vector3D(2000, 10, 100), InitialOrientation = new Orientation(Math.PI, 0.0, 0.0), InitialSpeed = 300, MaxSpeed = 400, - TargetIndex = 0, MaxFlightTime = 10, MaxFlightDistance = 3000, LaunchAcceleration = 50, MaxEngineBurnTime = 10, MaxAcceleration = 400, ProportionalNavigationCoefficient = 3, - ExplosionRadius = 10, + ExplosionRadius = 5, + HitProbability = 0.9, Mass = 50, Type = MissileType.LaserBeamRiderGuidance }, // 末敏弹配置 new() { Id = "TSM_1", + TargetId = "Tank_1", InitialPosition = new Vector3D(3000, 0, 100), // 发射位置 InitialOrientation = new Orientation(Math.PI, 0, 0), // 使用计算得到的发射角度 InitialSpeed = 800, MaxSpeed = 1000, - TargetIndex = 0, MaxFlightTime = 30, MaxFlightDistance = 5000, LaunchAcceleration = 0, @@ -126,23 +128,25 @@ namespace ActiveProtect MaxAcceleration = 10, ProportionalNavigationCoefficient = 3, ExplosionRadius = 5, + HitProbability = 0.9, Mass = 50, Type = MissileType.TerminalSensitiveMissile }, // 红外指令制导导弹配置 new() { Id = "ICGM_1", + TargetId = "Tank_1", InitialPosition = new Vector3D(2000, 10, 100), InitialOrientation = new Orientation(Math.PI, 0.0, 0), InitialSpeed = 300, MaxSpeed = 400, - TargetIndex = 0, MaxFlightTime = 60, MaxFlightDistance = 5000, LaunchAcceleration = 50, MaxEngineBurnTime = 10, MaxAcceleration = 100, ExplosionRadius = 5, + HitProbability = 0.9, ProportionalNavigationCoefficient = 3, Mass = 50, Type = MissileType.InfraredCommandGuidance @@ -150,17 +154,18 @@ namespace ActiveProtect // 红外成像末制导导弹配置 new() { Id = "ITGM_1", + TargetId = "Tank_1", InitialPosition = new Vector3D(2000, 100, 100), InitialOrientation = new Orientation(Math.PI, 0.0, 0), InitialSpeed = 300, MaxSpeed = 400, - TargetIndex = 0, MaxFlightTime = 60, MaxFlightDistance = 5000, LaunchAcceleration = 50, MaxEngineBurnTime = 10, MaxAcceleration = 50, - ExplosionRadius = 1, + ExplosionRadius = 5, + HitProbability = 0.9, ProportionalNavigationCoefficient = 3, Mass = 50, Type = MissileType.InfraredImagingTerminalGuidance @@ -168,17 +173,18 @@ namespace ActiveProtect // 毫米波导引头制导导弹配置 new() { Id = "MMWG_1", + TargetId = "Tank_1", InitialPosition = new Vector3D(2000, 10, 100), InitialOrientation = new Orientation(Math.PI, 0.0, 0), InitialSpeed = 300, MaxSpeed = 400, - TargetIndex = 0, MaxFlightTime = 60, MaxFlightDistance = 5000, LaunchAcceleration = 50, MaxEngineBurnTime = 10, MaxAcceleration = 50, - ExplosionRadius = 1, + ExplosionRadius = 5, + HitProbability = 0.9, ProportionalNavigationCoefficient = 3, Mass = 50, Type = MissileType.MillimeterWaveTerminalGuidance @@ -193,9 +199,9 @@ namespace ActiveProtect MaxTrackingRange = 10000, // 10公里 FieldOfView = Math.PI / 4, // 45度 AngleMeasurementAccuracy = 0.0005, // 0.0005弧度 (约0.029度) - UpdateFrequency = 10 // 20赫兹 + UpdateFrequency = 100 // 100赫兹 }, - SimulationTimeStep = 0.005 // 仿真时间步长, 激光驾束制导导弹需要更小的步长,< 0.025s + SimulationTimeStep = 0.01 // 仿真时间步长, 激光驾束制导导弹需要更小的步长,< 0.025s }; // 创建仿真管理器 @@ -208,7 +214,7 @@ namespace ActiveProtect { simulationManager.Update(); simulationManager.PrintStatus(); - Thread.Sleep(20); // 暂停100毫秒,使输出更易读 + Thread.Sleep(10); // 暂停100毫秒,使输出更易读 iteration++; } diff --git a/src/Models/Equipment/Tank.cs b/src/Models/Equipment/Tank.cs index e56ed7f..a190f95 100644 --- a/src/Models/Equipment/Tank.cs +++ b/src/Models/Equipment/Tank.cs @@ -9,56 +9,27 @@ namespace ActiveProtect.Models /// public class Tank : SimulationElement { - /// - /// 当前速度(米/秒) - /// - public double Speed { get; set; } - - /// - /// 最大速度(米/秒) - /// - public double MaxSpeed { get; private set; } - - /// - /// 最大装甲值 - /// - public double MaxArmor { get; private set; } - /// /// 当前装甲值 /// public double CurrentArmor { get; private set; } - /// - /// 红外辐射强度 (W/sr) - /// - public double InfraredRadiationIntensity { get; set; } - - /// - /// 雷达截面积 (m^2) - /// - public double RadarCrossSection { get; set; } - /// /// 坦克配置 /// - public TankConfig TankConfig { get; private set; } + public TankProperties TankProperties { get; private set; } /// /// 构造函数 /// - /// 坦克配置 + /// 坦克配置 /// 仿真管理器 - public Tank(TankConfig tankConfig, ISimulationManager simulationManager) - : base(tankConfig.Id, tankConfig.InitialPosition, tankConfig.InitialOrientation, tankConfig.InitialSpeed, simulationManager) + public Tank(TankProperties properties, ISimulationManager simulationManager) + : base(properties.Id, properties.InitialPosition, properties.InitialOrientation, properties.InitialSpeed, simulationManager) { - TankConfig = tankConfig; - Speed = TankConfig.InitialSpeed; - MaxSpeed = TankConfig.MaxSpeed; - MaxArmor = TankConfig.MaxArmor; - CurrentArmor = TankConfig.MaxArmor; - InfraredRadiationIntensity = TankConfig.InfraredRadiationIntensity; - RadarCrossSection = TankConfig.RadarCrossSection; + TankProperties = properties; + Speed = TankProperties.InitialSpeed; + CurrentArmor = TankProperties.MaxArmor; IsActive = false; } @@ -111,8 +82,8 @@ namespace ActiveProtect.Models { return $"坦克 {Id}:\n" + $" 位置: {Position}\n" + - $" 速度: {Speed:F2}/{MaxSpeed:F2}\n" + - $" 装甲: {CurrentArmor:F2}/{MaxArmor:F2}\n" + + $" 速度: {Speed:F2}/{TankProperties.MaxSpeed:F2}\n" + + $" 装甲: {CurrentArmor:F2}/{TankProperties.MaxArmor:F2}\n" + $" 状态: {(IsActive ? "活动" : "已销毁")}\n"; } } diff --git a/src/Models/Equipment/TankProperties.cs b/src/Models/Equipment/TankProperties.cs new file mode 100644 index 0000000..779f69e --- /dev/null +++ b/src/Models/Equipment/TankProperties.cs @@ -0,0 +1,102 @@ + using ActiveProtect.Utility; + +namespace ActiveProtect.Models +{ + /// + /// 坦克配置类 + /// + public class TankProperties + { + /// + /// 坦克ID + /// + public string Id { get; set; } + + /// + /// 初始位置 + /// + public Vector3D InitialPosition { get; set; } + + /// + /// 初始朝向 + /// + public Orientation InitialOrientation { get; set; } + + /// + /// 初始速度(米/秒) + /// + public double InitialSpeed { get; set; } + + /// + /// 最大速度(米/秒) + /// + public double MaxSpeed { get; set; } + + /// + /// 最大装甲值 + /// + public double MaxArmor { get; set; } + + /// + /// 红外辐射强度(W/sr) + /// + public double InfraredRadiationIntensity { get; set; } + + /// + /// 雷达截面积(m^2) + /// + public double RadarCrossSection { get; set; } + + /// + /// 是否装备激光告警器 + /// + public bool HasLaserWarner { get; set; } + + /// + /// 是否装备激光干扰器 + /// + public bool HasLaserJammer { get; set; } + + /// + /// 是否装备毫米波干扰器 + /// + public bool HasMillimeterWaveJammer { get; set; } + + /// + /// 构造函数,设置默认值 + /// + public TankProperties() + { + SetDefaultValues(); + + Id = ""; + InitialPosition = new Vector3D(0, 0, 0); + InitialOrientation = new Orientation(0, 0, 0); + } + + public TankProperties(TankInfo tankInfo){ + SetDefaultValues(); + + Id = $"Tank_{tankInfo.TankID}"; + InitialPosition = new Vector3D(tankInfo.xp, tankInfo.yp, tankInfo.zp); + InitialOrientation = new Orientation(0, 0, 0); + } + + public void SetDefaultValues(){ + InitialSpeed = 0; + MaxSpeed = 0; + MaxArmor = 0; + HasLaserWarner = false; + HasLaserJammer = false; + HasMillimeterWaveJammer = false; + InfraredRadiationIntensity = 0; + } + + // 验证方法 + public bool Validate() + { + // 实现验证逻辑 + return true; + } + } +} \ No newline at end of file diff --git a/src/Models/Guidance/InfraredImagingGuidanceSystem.cs b/src/Models/Guidance/InfraredImagingGuidanceSystem.cs index 9ae7d25..6e15160 100644 --- a/src/Models/Guidance/InfraredImagingGuidanceSystem.cs +++ b/src/Models/Guidance/InfraredImagingGuidanceSystem.cs @@ -38,7 +38,7 @@ namespace ActiveProtect.Models Vector3D targetVelocity = (tankPosition - lastTargetPosition) / deltaTime; lastTargetPosition = tankPosition; - // 使用基类的比例控制算法 + // 使用比例控制算法 GuidanceAcceleration = MotionAlgorithm.CalculateProportionalNavigation(ProportionalNavigationCoefficient, missilePosition, missileVelocity, tankPosition, targetVelocity); // 限制最大加速度 if (GuidanceAcceleration.Magnitude() > MaxAcceleration) @@ -74,6 +74,7 @@ namespace ActiveProtect.Models if (angle <= FIELD_OF_VIEW / 2) { double snr = CalculateSNR(tank, distance); + Console.WriteLine($"SNR: {snr}"); if (snr > RECOGNITION_SNR_THRESHOLD) { tankPosition = tank.Position; @@ -102,7 +103,7 @@ namespace ActiveProtect.Models /// private static double CalculateSNR(Tank tank, double distance) { - double targetRadiation = tank.InfraredRadiationIntensity; + double targetRadiation = tank.TankProperties.InfraredRadiationIntensity; double backgroundRadiation = BACKGROUND_RADIATION_INTENSITY; // 考虑距离衰减 diff --git a/src/Models/Guidance/MillimeterWaveGuidanceSystem.cs b/src/Models/Guidance/MillimeterWaveGuidanceSystem.cs index c95b6da..c876050 100644 --- a/src/Models/Guidance/MillimeterWaveGuidanceSystem.cs +++ b/src/Models/Guidance/MillimeterWaveGuidanceSystem.cs @@ -98,7 +98,7 @@ namespace ActiveProtect.Models if (angle <= FIELD_OF_VIEW / 2) { // 模拟毫米波探测 - double snr = CalculateSNR(distance, tank.RadarCrossSection); + double snr = CalculateSNR(distance, tank.TankProperties.RadarCrossSection); Console.WriteLine($" 80信噪比 {snr}"); if(snr > RECOGNITION_SNR_THRESHOLD && random.NextDouble() < TARGET_RECOGNITION_PROBABILITY) diff --git a/src/Models/MIssile/InfraredCommandGuidedMissile.cs b/src/Models/MIssile/InfraredCommandGuidedMissile.cs index e9ce256..46b9d54 100644 --- a/src/Models/MIssile/InfraredCommandGuidedMissile.cs +++ b/src/Models/MIssile/InfraredCommandGuidedMissile.cs @@ -45,7 +45,7 @@ namespace ActiveProtect.Models /// /// 构造函数 /// - public InfraredCommandGuidedMissile(MissileConfig config, ISimulationManager manager) : base(config, manager) + public InfraredCommandGuidedMissile(MissileProperties config, ISimulationManager manager) : base(config, manager) { infraredTracker = null!; RadiationPower = 1000; @@ -105,9 +105,10 @@ namespace ActiveProtect.Models /// 时间步长 private void UpdateCruiseStage(double deltaTime) { + HasGuidance = true; guidanceSystem.Update(deltaTime, Position, Velocity); GuidanceAcceleration = guidanceSystem.GetGuidanceAcceleration(); - if (DistanceToTarget <= ExplosionRadius) + if (DistanceToTarget <= MissileProperties.ExplosionRadius) { currentStage = ICGM_Stage.Explode; } diff --git a/src/Models/MIssile/InfraredImagingTerminalGuidedMissile.cs b/src/Models/MIssile/InfraredImagingTerminalGuidedMissile.cs index 774377b..f8f0efe 100644 --- a/src/Models/MIssile/InfraredImagingTerminalGuidedMissile.cs +++ b/src/Models/MIssile/InfraredImagingTerminalGuidedMissile.cs @@ -29,10 +29,9 @@ namespace ActiveProtect.Models /// /// 红外成像末制导导弹构造函数 /// - public InfraredImagingTerminalGuidedMissile(MissileConfig config, ISimulationManager manager) + public InfraredImagingTerminalGuidedMissile(MissileProperties config, ISimulationManager manager) : base(config, manager) { - Type = MissileType.InfraredImagingTerminalGuidance; currentStage = IRTG_Stage.Launch; guidanceSystem = new InfraredImagingGuidanceSystem(config.MaxAcceleration, config.ProportionalNavigationCoefficient, manager); } @@ -98,10 +97,11 @@ namespace ActiveProtect.Models /// private void UpdateTerminalGuidanceStage(double deltaTime) { + HasGuidance = true; guidanceSystem.Update(deltaTime, Position, Velocity); GuidanceAcceleration = guidanceSystem.GetGuidanceAcceleration(); - if (DistanceToTarget <= ExplosionRadius) + if (DistanceToTarget <= MissileProperties.ExplosionRadius) { currentStage = IRTG_Stage.Explode; } diff --git a/src/Models/MIssile/LaserBeamRiderMissile.cs b/src/Models/MIssile/LaserBeamRiderMissile.cs index 5d6bb56..5fbdca1 100644 --- a/src/Models/MIssile/LaserBeamRiderMissile.cs +++ b/src/Models/MIssile/LaserBeamRiderMissile.cs @@ -30,7 +30,7 @@ namespace ActiveProtect.Models /// /// 导弹配置 /// 模拟管理器 - public LaserBeamRiderMissile(MissileConfig config, ISimulationManager manager) + public LaserBeamRiderMissile(MissileProperties config, ISimulationManager manager) : base(config, manager) { LaserBeamRiderGuidanceSystem = new LaserBeamRiderGuidanceSystem(config.MaxAcceleration, config.ProportionalNavigationCoefficient); @@ -119,9 +119,10 @@ namespace ActiveProtect.Models private void UpdateCruiseStage(double deltaTime) { // 巡航阶段 + HasGuidance = true; LaserBeamRiderGuidanceSystem.Update(deltaTime, Position, Velocity); GuidanceAcceleration = LaserBeamRiderGuidanceSystem.GetGuidanceAcceleration(); - if (DistanceToTarget <= ExplosionRadius) + if (DistanceToTarget <= MissileProperties.ExplosionRadius) { currentStage = LBRM_Stage.Explode; } diff --git a/src/Models/MIssile/LaserSemiActiveGuidedMissile.cs b/src/Models/MIssile/LaserSemiActiveGuidedMissile.cs index 3a2e3c4..3e213cb 100644 --- a/src/Models/MIssile/LaserSemiActiveGuidedMissile.cs +++ b/src/Models/MIssile/LaserSemiActiveGuidedMissile.cs @@ -30,7 +30,7 @@ namespace ActiveProtect.Models /// 激光指示器ID /// 导弹配置 /// 仿真管理器 - public LaserSemiActiveGuidedMissile(MissileConfig config, ISimulationManager manager) + public LaserSemiActiveGuidedMissile(MissileProperties config, ISimulationManager manager) : base(config, manager) { LaserGuidanceSystem = new LaserSemiActiveGuidanceSystem(config.MaxAcceleration, config.ProportionalNavigationCoefficient); @@ -139,9 +139,10 @@ namespace ActiveProtect.Models /// 时间步长 private void UpdateCruiseStage(double deltaTime) { + HasGuidance = true; LaserGuidanceSystem.Update(deltaTime, Position, Velocity); GuidanceAcceleration = LaserGuidanceSystem.GetGuidanceAcceleration(); - if (DistanceToTarget <= ExplosionRadius) + if (DistanceToTarget <= MissileProperties.ExplosionRadius) { currentStage = LSAGM_Stage.Explode; } diff --git a/src/Models/MIssile/MillimeterWaveTerminalGuidedMissile.cs b/src/Models/MIssile/MillimeterWaveTerminalGuidedMissile.cs index c1189a7..a04f6ca 100644 --- a/src/Models/MIssile/MillimeterWaveTerminalGuidedMissile.cs +++ b/src/Models/MIssile/MillimeterWaveTerminalGuidedMissile.cs @@ -28,12 +28,11 @@ namespace ActiveProtect.Models /// /// 毫米波末制导导弹构造函数 /// - public MillimeterWaveTerminalGuidedMissile(MissileConfig config, ISimulationManager manager) - : base(config, manager) + public MillimeterWaveTerminalGuidedMissile(MissileProperties properties, ISimulationManager manager) + : base(properties, manager) { - Type = MissileType.MillimeterWaveTerminalGuidance; currentStage = MWTG_Stage.Launch; - guidanceSystem = new MillimeterWaveGuidanceSystem(config.MaxAcceleration, config.ProportionalNavigationCoefficient, manager); + guidanceSystem = new MillimeterWaveGuidanceSystem(properties.MaxAcceleration, properties.ProportionalNavigationCoefficient, manager); } /// @@ -99,10 +98,11 @@ namespace ActiveProtect.Models /// private void UpdateTerminalGuidanceStage(double deltaTime) { + HasGuidance = true; guidanceSystem.Update(deltaTime, Position, Velocity); GuidanceAcceleration = guidanceSystem.GetGuidanceAcceleration(); - if (DistanceToTarget <= ExplosionRadius) + if (DistanceToTarget <= MissileProperties.ExplosionRadius) { currentStage = MWTG_Stage.Explode; Console.WriteLine($"导弹 {Id} 进入爆炸阶段"); diff --git a/src/Models/MIssile/MissileBase.cs b/src/Models/MIssile/MissileBase.cs index 84be168..d0ce940 100644 --- a/src/Models/MIssile/MissileBase.cs +++ b/src/Models/MIssile/MissileBase.cs @@ -5,41 +5,12 @@ using ActiveProtect.Utility; namespace ActiveProtect.Models { + /// /// 表示仿真中的导弹 /// public class MissileBase : SimulationElement - { - /// - /// 导弹类型 - /// - public MissileType Type { get; protected set; } - - /// - /// 当前速度(米/秒) - /// - public double Speed { get; protected set; } - - /// - /// 最大速度(米/秒) - /// - public double MaxSpeed { get; protected set; } - - /// - /// 目标ID - /// - public string TargetId { get; protected set; } - - /// - /// 最大飞行时间(秒) - /// - public double MaxFlightTime { get; protected set; } - - /// - /// 最大飞行距离(米) - /// - public double MaxFlightDistance { get; protected set; } - + { /// /// 当前飞行时间(秒) /// @@ -55,45 +26,10 @@ namespace ActiveProtect.Models /// public double DistanceToTarget { get; protected set; } - /// - /// 爆炸半径(米) - /// - public double ExplosionRadius { get; protected set; } - - /// - /// 上一帧目标位置 - /// - private Vector3D LastTargetPosition; - - /// - /// 比例导引系数 - /// - private const double N = 3; - - /// - /// 推力加速度(米/秒²) - /// - public double LaunchAcceleration { get; protected set; } - /// /// 当前发动机燃烧时间(秒) /// public double EngineBurnTime { get; protected set; } - - /// - /// 最大发动机燃烧时间(秒) - /// - public double MaxEngineBurnTime { get; protected set; } - - /// - /// 最大加速度(米/秒²) - /// - public double MaxAcceleration { get; protected set; } - - /// - /// 比例导引系数 - /// - public double ProportionalNavigationCoefficient { get; set; } /// /// 是否有制导 @@ -110,11 +46,6 @@ namespace ActiveProtect.Models /// protected Vector3D LastKnownVelocity = Vector3D.Zero; - /// - /// 导弹质量(千克) - /// - public double Mass { get; protected set; } - /// /// 制导加速度 /// @@ -125,17 +56,19 @@ namespace ActiveProtect.Models /// protected Vector3D ThrustAcceleration { get; set; } - protected readonly MissileConfig MissileConfig; + /// + /// 导弹固定配置参数 + /// + public readonly MissileProperties MissileProperties; /// /// 构造函数 /// - public MissileBase(MissileConfig config, ISimulationManager manager) - : base(config.Id, config.InitialPosition, config.InitialOrientation, config.InitialSpeed, manager) + public MissileBase(MissileProperties properties, ISimulationManager manager) + : base(properties.Id, properties.InitialPosition, properties.InitialOrientation, properties.InitialSpeed, manager) { - MissileConfig = config; + MissileProperties = properties; SimulationManager = manager; - InitializeFromConfig(); IsActive = false; HasGuidance = false; @@ -144,26 +77,7 @@ namespace ActiveProtect.Models EngineBurnTime = 0; GuidanceAcceleration = Vector3D.Zero; ThrustAcceleration = Vector3D.Zero; - LastTargetPosition = Vector3D.Zero; - TargetId = $"Tank_{config.TargetIndex + 1}"; - DistanceToTarget = Vector3D.Distance(Position, SimulationManager.GetEntityById(TargetId).Position); - } - - /// - /// 从配置初始化导弹 - /// - private void InitializeFromConfig() - { - // 初始化导弹属性 - Speed = MissileConfig.InitialSpeed; - MaxSpeed = MissileConfig.MaxSpeed; - MaxFlightTime = MissileConfig.MaxFlightTime; - MaxFlightDistance = MissileConfig.MaxFlightDistance; - ExplosionRadius = MissileConfig.ExplosionRadius; - LaunchAcceleration = MissileConfig.LaunchAcceleration; - MaxEngineBurnTime = MissileConfig.MaxEngineBurnTime; - MaxAcceleration = MissileConfig.MaxAcceleration; - ProportionalNavigationCoefficient = MissileConfig.ProportionalNavigationCoefficient; + DistanceToTarget = Vector3D.Distance(Position, SimulationManager.GetEntityById(properties.TargetId).Position); } /// @@ -192,7 +106,6 @@ namespace ActiveProtect.Models } else { - Console.WriteLine($"无制导条件下,使用运动学方程更新导弹的位置和速度"); // 无制导条件下,使用运动学方程更新导弹的位置和速度 (Position, Velocity) = MotionAlgorithm.CalculateBallisticMotion(Position, Velocity, acceleration, deltaTime); } @@ -200,16 +113,21 @@ namespace ActiveProtect.Models // 限制速度不超过最大速度 - if (Velocity.Magnitude() > MaxSpeed) + if (Velocity.Magnitude() > MissileProperties.MaxSpeed) { - Velocity = Velocity.Normalize() * MaxSpeed; + Velocity = Velocity.Normalize() * MissileProperties.MaxSpeed; } Speed = Velocity.Magnitude(); Orientation = Orientation.FromVector(Velocity); + + // 添加高斯噪声(测试用,用于测试运动中概率的影响) + // Position = MotionAlgorithm.AddRandomPerturbation(Position); + // Velocity = MotionAlgorithm.AddRandomPerturbation(Velocity); + FlightTime += deltaTime; FlightDistance += Speed * deltaTime; - DistanceToTarget = Vector3D.Distance(Position, SimulationManager.GetEntityById(TargetId).Position); + DistanceToTarget = Vector3D.Distance(Position, SimulationManager.GetEntityById(MissileProperties.TargetId).Position); } /// @@ -218,14 +136,14 @@ namespace ActiveProtect.Models private Vector3D CalculateAcceleration(Vector3D velocity) { // 计算空气阻力的影响 - Vector3D dragAcceleration = velocity.Normalize() * -1 * CalculateDrag(velocity.Magnitude()) / Mass; + Vector3D dragAcceleration = velocity.Normalize() * -1 * CalculateDrag(velocity.Magnitude()) / MissileProperties.Mass; Vector3D totalAcceleration = GuidanceAcceleration + ThrustAcceleration + dragAcceleration; Console.WriteLine($"导弹 {Id} 的加速度: {totalAcceleration}, 制导加速度: {GuidanceAcceleration}, 推力加速度: {ThrustAcceleration}, 空气阻力加速度: {dragAcceleration}"); - if (totalAcceleration.Magnitude() > MaxAcceleration) + if (totalAcceleration.Magnitude() > MissileProperties.MaxAcceleration) { - totalAcceleration = totalAcceleration.Normalize() * MaxAcceleration; + totalAcceleration = totalAcceleration.Normalize() * MissileProperties.MaxAcceleration; } return totalAcceleration; @@ -248,14 +166,14 @@ namespace ActiveProtect.Models /// protected bool ShouldSelfDestruct() { - if (FlightTime >= MaxFlightTime) + if (FlightTime >= MissileProperties.MaxFlightTime) { - Console.WriteLine($"导弹 {Id} 超出最大飞行时间 ({FlightTime:F2}/{MaxFlightTime:F2}),准备自毁"); + Console.WriteLine($"导弹 {Id} 超出最大飞行时间 ({FlightTime:F2}/{MissileProperties.MaxFlightTime:F2}),准备自毁"); return true; } - if (FlightDistance >= MaxFlightDistance) + if (FlightDistance >= MissileProperties.MaxFlightDistance) { - Console.WriteLine($"导弹 {Id} 超出最大飞行距离 ({FlightDistance:F2}/{MaxFlightDistance:F2}),准备自毁"); + Console.WriteLine($"导弹 {Id} 超出最大飞行距离 ({FlightDistance:F2}/{MissileProperties.MaxFlightDistance:F2}),准备自毁"); return true; } if (Position.Y <= -1.0) // 数字略小于0 @@ -283,8 +201,7 @@ namespace ActiveProtect.Models protected virtual void Explode() { Deactivate(); - SimulationManager.HandleTargetHit(TargetId, Id); - Console.WriteLine($"导弹 {Id} 在 {Position} 爆炸,命中目标!"); + SimulationManager.HandleTargetHit(MissileProperties.TargetId, Id); } /// @@ -294,8 +211,8 @@ namespace ActiveProtect.Models { if (IsActive) { - string reason = FlightTime >= MaxFlightTime ? "超出最大飞行时间" : - FlightDistance >= MaxFlightDistance ? "超出最大飞行距离" : + string reason = FlightTime >= MissileProperties.MaxFlightTime ? "超出最大飞行时间" : + FlightDistance >= MissileProperties.MaxFlightDistance ? "超出最大飞行距离" : Position.Y <= 0 ? "高度小于等于0" : !HasGuidance ? "失去引导" : "未知原因"; @@ -304,15 +221,6 @@ namespace ActiveProtect.Models } } - /// - /// 设置比例导引系数 - /// - public void SetProportionalNavigationCoefficient(double newCoefficient) - { - ProportionalNavigationCoefficient = newCoefficient; - Console.WriteLine($"导弹 {Id} 的比例导引系数已更新为 {newCoefficient}"); - } - /// /// 获取导弹状态 /// @@ -324,10 +232,10 @@ namespace ActiveProtect.Models $" 速度: {missileRunningState.Speed:F2} m/s\n" + $" 速度分量: {missileRunningState.Velocity}\n" + $" 朝向: {missileRunningState.Orientation}\n" + - $" 飞行时间: {missileRunningState.FlightTime:F2}/{MaxFlightTime:F2}\n" + - $" 飞行距离: {missileRunningState.FlightDistance:F2}/{MaxFlightDistance:F2}\n" + + $" 飞行时间: {missileRunningState.FlightTime:F2}/{MissileProperties.MaxFlightTime:F2}\n" + + $" 飞行距离: {missileRunningState.FlightDistance:F2}/{MissileProperties.MaxFlightDistance:F2}\n" + $" 距离目标: {missileRunningState.DistanceToTarget:F2}\n" + - $" 发动机工作时间: {missileRunningState.EngineBurnTime:F2}/{MaxEngineBurnTime:F2}\n" + + $" 发动机工作时间: {missileRunningState.EngineBurnTime:F2}/{MissileProperties.MaxEngineBurnTime:F2}\n" + $" 有引导: {(missileRunningState.HasGuidance ? "是" : "否")}\n" + $" 失去引导时间: {missileRunningState.LostGuidanceTime:F2}\n"; } @@ -345,12 +253,11 @@ namespace ActiveProtect.Models return new MissileRunningState { Id = Id, - Type = Type, + Type = MissileProperties.Type, Position = Position, Velocity = Velocity, Orientation = Orientation, Speed = Speed, - TargetId = TargetId, FlightTime = FlightTime, FlightDistance = FlightDistance, DistanceToTarget = DistanceToTarget, @@ -397,11 +304,6 @@ namespace ActiveProtect.Models /// public double Speed { get; set; } - /// - /// 目标ID - /// - public string TargetId { get; set; } - /// /// 当前飞行时间(秒) /// diff --git a/src/Models/MIssile/MissileProperties.cs b/src/Models/MIssile/MissileProperties.cs new file mode 100644 index 0000000..c9b9b95 --- /dev/null +++ b/src/Models/MIssile/MissileProperties.cs @@ -0,0 +1,147 @@ +using System.Runtime; +using ActiveProtect.Utility; + +namespace ActiveProtect.Models +{ + /// + /// 导弹类型枚举 + /// + public enum MissileType + { + StandardMissile, // 标准导弹 + LaserSemiActiveGuidance, // 激光半主动制导 + LaserBeamRiderGuidance, // 激光驾束制导 + InfraredCommandGuidance, // 红外指令制导 + InfraredImagingTerminalGuidance, // 红外成像末制导 + MillimeterWaveTerminalGuidance, // 毫米波末制导 + TerminalSensitiveMissile // 末敏弹 + } + + /// + /// 导弹配置类 + /// + public class MissileProperties + { + /// + /// 导弹ID + /// + public string Id { get; set; } + + /// + /// 目标ID + /// + public string TargetId { get; set; } + + /// + /// 初始位置 + /// + public Vector3D InitialPosition { get; set; } + + /// + /// 初始朝向 + /// + public Orientation InitialOrientation { get; set; } + + /// + /// 初始速度(米/秒) + /// + public double InitialSpeed { get; set; } + + /// + /// 最大速度(米/秒) + /// + public double MaxSpeed { get; set; } + + /// + /// 最大飞行时间(秒) + /// + public double MaxFlightTime { get; set; } + + /// + /// 最大飞行距离(米) + /// + public double MaxFlightDistance { get; set; } + + /// + /// 最大加速度(米/秒²) + /// + public double MaxAcceleration { get; set; } + + /// + /// 比例导引系数 + /// + public double ProportionalNavigationCoefficient { get; set; } + + /// + /// 发射推力加速度(米/秒²) + /// + public double LaunchAcceleration { get; set; } + + /// + /// 最大发动机燃烧时间(秒) + /// + public double MaxEngineBurnTime { get; set; } + + /// + /// 导弹质量(千克) + /// + public double Mass { get; set; } + + /// + /// 爆炸半径(米) + /// + public double ExplosionRadius { get; set; } + + /// + /// 命中概率 + /// + public double HitProbability { get; set; } + + /// + /// 导弹类型 + /// + public MissileType Type { get; set; } + + /// + /// 构造函数,设置默认值 + /// + public MissileProperties() + { + SetDefaultValues(); + + Id = ""; + TargetId = ""; + InitialPosition = new Vector3D(0, 0, 0); + InitialOrientation = new Orientation(0, 0, 0); + Type = MissileType.LaserSemiActiveGuidance; + } + /// + /// 构造函数,根据导弹初始信息初始化导弹配置 + /// + /// 导弹初始信息 + public MissileProperties(MIniInfo mIniInfo){ + SetDefaultValues(); + + Id = $"Missile_{mIniInfo.nMisID}"; + TargetId = ""; + InitialPosition = new Vector3D(mIniInfo.xm, mIniInfo.ym, mIniInfo.zm); + InitialOrientation = new Orientation(mIniInfo.psi_m, mIniInfo.theta_m, 0); + InitialSpeed = mIniInfo.vm; + } + + /// + /// 设置默认值 + /// + public void SetDefaultValues(){ + InitialSpeed = 0; + MaxSpeed = 0; + MaxFlightTime = 0; + MaxFlightDistance = 0; + LaunchAcceleration = 0; + MaxEngineBurnTime = 0; + MaxAcceleration = 0; + ExplosionRadius = 0; + ProportionalNavigationCoefficient = 0; + } + } +} \ No newline at end of file diff --git a/src/Models/MIssile/TerminalSensitiveMissile.cs b/src/Models/MIssile/TerminalSensitiveMissile.cs index 87f184a..c8e1bcd 100644 --- a/src/Models/MIssile/TerminalSensitiveMissile.cs +++ b/src/Models/MIssile/TerminalSensitiveMissile.cs @@ -11,10 +11,8 @@ namespace ActiveProtect.Models private const double SeparationHeight = 1000; // 分离点距离目标水平距离,默认 1000 米 private const double SeparationDistance = 1000; - // 分离时距离分离点的距离阈值,默认 50米 - private const double SeparationRange = 0.5; - // 分离时距目标距离阈值,默认 1200 米 - private const double SeparationTargetDistance = 1200; + // 分离时距离分离点的距离阈值,默认 5米,必须 > 导弹速度 * 时间步长 / 2 + private const double SeparationRange = 5; // 子弹数量, 155 口径母弹,默认 2 个 private const int SubmunitionCount = 1; // 子弹数组 @@ -22,13 +20,14 @@ namespace ActiveProtect.Models // 分离点位置 private readonly Vector3D separationPoint; - public TerminalSensitiveMissile(MissileConfig config, ISimulationManager manager) - : base(config, manager) + public TerminalSensitiveMissile(MissileProperties properties, ISimulationManager manager) + : base(properties, manager) { submunitions = new TerminalSensitiveSubmunition[SubmunitionCount]; - //计算分离点坐标,高度为SeparationHeight,距离目标的距离为SeparationDistance - separationPoint = Vector3D.PointOnLine(base.SimulationManager.GetEntityById(TargetId).Position, base.Position, SeparationDistance) + new Vector3D(0, SeparationHeight, 0); + separationPoint = Vector3D.PointOnLine(base.SimulationManager.GetEntityById(properties.TargetId).Position, base.Position, SeparationDistance) + new Vector3D(0, SeparationHeight, 0); + + Console.WriteLine($"Position: {Position}, 分离点: {separationPoint}, speed: {Speed}, Speed: {properties.InitialSpeed}"); //计算导弹发射角度 (Orientation? launchOrientation, Vector3D? launchVelocity) = MotionAlgorithm.CalculateBestLaunchOrientation(Position, separationPoint, Speed); @@ -58,11 +57,8 @@ namespace ActiveProtect.Models Console.WriteLine($"分离点距离: {(separationPoint - Position).Magnitude()}"); - //计算到目标的距离 - double distanceToTarget = (SimulationManager.GetEntityById(TargetId).Position - Position).Magnitude(); - - //距离分离点距离小于50米,或者距离目标小于1400米,则分离 - if ((separationPoint - Position).Magnitude() <= SeparationRange || distanceToTarget <= SeparationTargetDistance) + //距离分离点距离小于50米,则分离 + if ((separationPoint - Position).Magnitude() <= SeparationRange) { Console.WriteLine("分离"); PerformSeparation(); @@ -75,30 +71,30 @@ namespace ActiveProtect.Models private void PerformSeparation() { // 获取目标位置 - Vector3D targetPosition = SimulationManager.GetEntityById(TargetId).Position; + Vector3D targetPosition = SimulationManager.GetEntityById(MissileProperties.TargetId).Position; + // 计算子弹朝向目标的方向 + Vector3D directionToTarget = (targetPosition - this.Position).Normalize(); + Orientation orientationToTarget = Orientation.FromVector(directionToTarget); // 创建并释子弹 for (int i = 0; i < SubmunitionCount; i++) { - // 计算子弹朝向目标的方向 - Vector3D directionToTarget = (targetPosition - this.Position).Normalize(); - Orientation orientationToTarget = Orientation.FromVector(directionToTarget); - submunitions[i] = new TerminalSensitiveSubmunition( - new MissileConfig + new MissileProperties { Id = $"{Id}_Sub_{i}", - InitialPosition = this.Position, - InitialOrientation = orientationToTarget, // 设置为朝向目标的方向 + TargetId = MissileProperties.TargetId, + InitialPosition = Position, + InitialOrientation = orientationToTarget, InitialSpeed = 200, // 子弹初始速度 MaxSpeed = 2000, - TargetIndex = 0, MaxFlightTime = 50, MaxFlightDistance = 1000, MaxAcceleration = 50, ProportionalNavigationCoefficient = 3, Mass = 10, - ExplosionRadius = this.ExplosionRadius + ExplosionRadius = MissileProperties.ExplosionRadius, + HitProbability = MissileProperties.HitProbability }, SimulationManager); diff --git a/src/Models/MIssile/TerminalSensitiveSubmunition.cs b/src/Models/MIssile/TerminalSensitiveSubmunition.cs index ab869f6..d9c1e95 100644 --- a/src/Models/MIssile/TerminalSensitiveSubmunition.cs +++ b/src/Models/MIssile/TerminalSensitiveSubmunition.cs @@ -62,10 +62,10 @@ namespace ActiveProtect.Models /// /// 构造函数 /// - /// 导弹配置 + /// 导弹配置 /// 模拟管理器 - public TerminalSensitiveSubmunition(MissileConfig config, ISimulationManager manager) - : base(config, manager) + public TerminalSensitiveSubmunition(MissileProperties properties, ISimulationManager manager) + : base(properties, manager) { currentStage = SubmunitionStage.Separation; spiralAngle = 0; @@ -226,11 +226,10 @@ namespace ActiveProtect.Models { Console.WriteLine("攻击阶段"); // 攻击逻辑 - Vector3D targetPosition = SimulationManager.GetEntityById(TargetId).Position; + Vector3D targetPosition = SimulationManager.GetEntityById(MissileProperties.TargetId).Position; Vector3D direction = (targetPosition - Position).Normalize(); Velocity = direction * AttackSpeed; - Console.WriteLine($"导弹ID: {Id}, 距离目标: {DistanceToTarget}, 爆炸半径: {ExplosionRadius}"); - if (DistanceToTarget <= ExplosionRadius) + if ((targetPosition - Position).Magnitude() <= MissileProperties.ExplosionRadius) { currentStage = SubmunitionStage.Explode; } @@ -259,7 +258,7 @@ namespace ActiveProtect.Models /// 是否检测到目标 private bool DetectTarget(Vector3D scanDirection) { - Vector3D targetPosition = SimulationManager.GetEntityById(TargetId).Position; + Vector3D targetPosition = SimulationManager.GetEntityById(MissileProperties.TargetId).Position; Vector3D toTarget = (targetPosition - Position).Normalize(); // 检查目标是否在扫描线上 diff --git a/src/Models/Sensor/MillimeterWaveRadiometer.cs b/src/Models/Sensor/MillimeterWaveRadiometer.cs index c25fe62..7bc7958 100644 --- a/src/Models/Sensor/MillimeterWaveRadiometer.cs +++ b/src/Models/Sensor/MillimeterWaveRadiometer.cs @@ -7,27 +7,30 @@ namespace ActiveProtect.Models public class MillimeterWaveRadiometer : Sensor { /// - /// 工作频率(3mm 或 8mm) + /// 工作波段(3mm 或 8mm) /// - public double Frequency { get; set; } + public double Wavelength { get; set; } /// /// 辐射温度差检测阈值,辐射计高温物体与低温物体的检测温差,单位K,默认 50K /// public double DetectionTemperatureDifferenceThreshold { get; set; } = 50; + private double lastDetectionTemperature = 0; + /// /// 构造函数 /// /// 辐射计的位置 /// 辐射计的朝向 - /// 工作频率 + /// 工作波段 /// 辐射温差检测阈值 - public MillimeterWaveRadiometer(Vector3D position, Orientation orientation, double frequency, double detectionTemperatureDifferenceThreshold) + public MillimeterWaveRadiometer(Vector3D position, Orientation orientation, double wavelength, double detectionTemperatureDifferenceThreshold) : base(position, orientation) { - Frequency = frequency; + Wavelength = wavelength; DetectionTemperatureDifferenceThreshold = detectionTemperatureDifferenceThreshold; + lastDetectionTemperature = 0; } /// diff --git a/src/Simulation/SimulationConfig.cs b/src/Simulation/SimulationConfig.cs index d8d837b..754502c 100644 --- a/src/Simulation/SimulationConfig.cs +++ b/src/Simulation/SimulationConfig.cs @@ -13,12 +13,12 @@ namespace ActiveProtect.Simulation /// /// 坦克配置列表 /// - public List TankConfigs { get; set; } + public List TankConfigs { get; set; } /// /// 导弹配置列表 /// - public List MissileConfigs { get; set; } + public List MissileConfigs { get; set; } /// /// 激光指示器配置列表 @@ -60,8 +60,8 @@ namespace ActiveProtect.Simulation /// public SimulationConfig() { - TankConfigs = new List(); - MissileConfigs = new List(); + TankConfigs = new List(); + MissileConfigs = new List(); LaserDesignatorConfig = new LaserDesignatorConfig(); LaserBeamRiderConfig = new LaserBeamRiderConfig(); LaserWarnerConfig = new LaserWarnerConfig(); @@ -72,250 +72,6 @@ namespace ActiveProtect.Simulation } } - /// - /// 坦克配置类 - /// - public class TankConfig - { - /// - /// 坦克ID - /// - public string Id { get; set; } - - /// - /// 初始位置 - /// - public Vector3D InitialPosition { get; set; } - - /// - /// 初始朝向 - /// - public Orientation InitialOrientation { get; set; } - - /// - /// 初始速度(米/秒) - /// - public double InitialSpeed { get; set; } - - /// - /// 最大速度(米/秒) - /// - public double MaxSpeed { get; set; } - - /// - /// 最大装甲值 - /// - public double MaxArmor { get; set; } - - /// - /// 红外辐射强度(W/sr) - /// - public double InfraredRadiationIntensity { get; set; } - - /// - /// 雷达截面积(m^2) - /// - public double RadarCrossSection { get; set; } - - /// - /// 是否装备激光告警器 - /// - public bool HasLaserWarner { get; set; } - - /// - /// 是否装备激光干扰器 - /// - public bool HasLaserJammer { get; set; } - - /// - /// 是否装备毫米波干扰器 - /// - public bool HasMillimeterWaveJammer { get; set; } - - /// - /// 构造函数,设置默认值 - /// - public TankConfig() - { - SetDefaultValues(); - - Id = ""; - InitialPosition = new Vector3D(0, 0, 0); - InitialOrientation = new Orientation(0, 0, 0); - } - - public TankConfig(TankInfo tankInfo){ - SetDefaultValues(); - - Id = $"Tank_{tankInfo.TankID}"; - InitialPosition = new Vector3D(tankInfo.xp, tankInfo.yp, tankInfo.zp); - InitialOrientation = new Orientation(0, 0, 0); - } - - public void SetDefaultValues(){ - InitialSpeed = 0; - MaxSpeed = 0; - MaxArmor = 0; - HasLaserWarner = false; - HasLaserJammer = false; - HasMillimeterWaveJammer = false; - InfraredRadiationIntensity = 0; - } - - // 验证方法 - public bool Validate() - { - // 实现验证逻辑 - return true; - } - } - - /// - /// 导弹配置类 - /// - public class MissileConfig - { - /// - /// 导弹ID - /// - public string Id { get; set; } - - /// - /// 初始位置 - /// - public Vector3D InitialPosition { get; set; } - - /// - /// 初始朝向 - /// - public Orientation InitialOrientation { get; set; } - - /// - /// 初始速度(米/秒) - /// - public double InitialSpeed { get; set; } - - /// - /// 最大速度(米/秒) - /// - public double MaxSpeed { get; set; } - - /// - /// 目标索引 - /// - public int TargetIndex { get; set; } - - /// - /// 最大飞行时间(秒) - /// - public double MaxFlightTime { get; set; } - - /// - /// 最大飞行距离(米) - /// - public double MaxFlightDistance { get; set; } - - /// - /// 最大加速度(米/秒²) - /// - public double MaxAcceleration { get; set; } - - /// - /// 比例导引系数 - /// - public double ProportionalNavigationCoefficient { get; set; } - - /// - /// 发射推力加速度(米/秒²) - /// - public double LaunchAcceleration { get; set; } - - /// - /// 最大发动机燃烧时间(秒) - /// - public double MaxEngineBurnTime { get; set; } - - /// - /// 导弹质量(千克) - /// - public double Mass { get; set; } - - /// - /// 爆炸半径(米) - /// - public double ExplosionRadius { get; set; } - - /// - /// 导弹类型 - /// - public MissileType Type { get; set; } - - /// - /// 比例增益 - /// - public double Kp { get; set; } - - /// - /// 积分增益 - /// - public double Ki { get; set; } - - /// - /// 微分增益 - /// - public double Kd { get; set; } - - /// - /// 自适应速率 - /// - public double AdaptiveRate { get; set; } - - /// - /// 期望性能指标 - /// - public double DesiredPerformance { get; set; } - - /// - /// 构造函数,设置默认值 - /// - public MissileConfig() - { - SetDefaultValues(); - - Id = ""; - InitialPosition = new Vector3D(0, 0, 0); - InitialOrientation = new Orientation(0, 0, 0); - } - /// - /// 构造函数,根据导弹初始信息初始化导弹配置 - /// - /// 导弹初始信息 - public MissileConfig(MIniInfo mIniInfo){ - SetDefaultValues(); - - Id = $"Missile_{mIniInfo.nMisID}"; - InitialPosition = new Vector3D(mIniInfo.xm, mIniInfo.ym, mIniInfo.zm); - InitialOrientation = new Orientation(mIniInfo.psi_m, mIniInfo.theta_m, 0); - InitialSpeed = mIniInfo.vm; - } - /// - /// 设置默认值 - /// - public void SetDefaultValues(){ - InitialSpeed = 0; - MaxSpeed = 0; - TargetIndex = 0; - MaxFlightTime = 0; - MaxFlightDistance = 0; - LaunchAcceleration = 0; - MaxEngineBurnTime = 0; - MaxAcceleration = 0; - ExplosionRadius = 0; - ProportionalNavigationCoefficient = 0; - Type = MissileType.StandardMissile; - } - } - /// /// 激光指示器配置类 /// @@ -396,19 +152,7 @@ namespace ActiveProtect.Simulation } } - /// - /// 导弹类型枚举 - /// - public enum MissileType - { - StandardMissile, // 标准导弹 - LaserSemiActiveGuidance, // 激光半主动制导 - LaserBeamRiderGuidance, // 激光驾束制导 - InfraredCommandGuidance, // 红外指令制导 - InfraredImagingTerminalGuidance, // 红外成像末制导 - MillimeterWaveTerminalGuidance, // 毫米波末制导 - TerminalSensitiveMissile // 末敏弹 - } + /// diff --git a/src/Simulation/SimulationElement.cs b/src/Simulation/SimulationElement.cs index 846f096..e91d17a 100644 --- a/src/Simulation/SimulationElement.cs +++ b/src/Simulation/SimulationElement.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection.Metadata.Ecma335; using ActiveProtect.Utility; namespace ActiveProtect.Simulation @@ -21,6 +22,11 @@ namespace ActiveProtect.Simulation /// /// 仿真元素的当前速度 /// + public virtual double Speed { get; set; } + + /// + /// 仿真元素的当前速度向量 + /// public virtual Vector3D Velocity { get; set; } /// @@ -50,6 +56,7 @@ namespace ActiveProtect.Simulation Id = id; Position = position; Orientation = orientation; + Speed = speed; Velocity = orientation.ToVector() * speed; this.SimulationManager = simulationManager; IsActive = false; diff --git a/src/Simulation/SimulationManager.cs b/src/Simulation/SimulationManager.cs index 195d25b..d7c0362 100644 --- a/src/Simulation/SimulationManager.cs +++ b/src/Simulation/SimulationManager.cs @@ -148,36 +148,34 @@ namespace ActiveProtect.Simulation } } - - // 创建导弹 for (int i = 0; i < config.MissileConfigs.Count; i++) { - var missileConfig = config.MissileConfigs[i]; + var missileProperties = config.MissileConfigs[i]; MissileBase missile; - switch (missileConfig.Type) + switch (missileProperties.Type) { case MissileType.LaserSemiActiveGuidance: - missile = new LaserSemiActiveGuidedMissile(missileConfig, this); + missile = new LaserSemiActiveGuidedMissile(missileProperties, this); break; case MissileType.LaserBeamRiderGuidance: - missile = new LaserBeamRiderMissile(missileConfig, this); + missile = new LaserBeamRiderMissile(missileProperties, this); break; case MissileType.TerminalSensitiveMissile: - missile = new TerminalSensitiveMissile(missileConfig, this); + missile = new TerminalSensitiveMissile(missileProperties, this); break; case MissileType.InfraredCommandGuidance: - missile = new InfraredCommandGuidedMissile(missileConfig, this); + missile = new InfraredCommandGuidedMissile(missileProperties, this); break; case MissileType.InfraredImagingTerminalGuidance: - missile = new InfraredImagingTerminalGuidedMissile(missileConfig, this); + missile = new InfraredImagingTerminalGuidedMissile(missileProperties, this); break; case MissileType.MillimeterWaveTerminalGuidance: - missile = new MillimeterWaveTerminalGuidedMissile(missileConfig, this); + missile = new MillimeterWaveTerminalGuidedMissile(missileProperties, this); break; default: - missile = new MissileBase(missileConfig, this); + missile = new MissileBase(missileProperties, this); break; } @@ -223,10 +221,10 @@ namespace ActiveProtect.Simulation Elements.Add(infraredTracker); // 激活所有元素 - //ActivateAllElements(); + ActivateAllElements(); // 激活部分元素 - ActivateSomeElements(); + //ActivateSomeElements(); } //激活所有元素 @@ -431,6 +429,15 @@ namespace ActiveProtect.Simulation { if (GetEntityById(targetId) is Tank tank && GetEntityById(missileId) is MissileBase missile) { + // 生成随机数决定是否命中 + Random random = new(); + //bool isHit = random.NextDouble() <= missile.MissileProperties.HitProbability; + bool isHit = true; + if (!isHit) + { + Console.WriteLine($"导弹 {missileId} 未命中目标 {targetId}"); + return; + } // 计算导弹造成的伤害 double damage = CalculateMissileDamage(missile); diff --git a/src/Utility/MotionAlgorithm.cs b/src/Utility/MotionAlgorithm.cs index f59a7d5..95ef286 100644 --- a/src/Utility/MotionAlgorithm.cs +++ b/src/Utility/MotionAlgorithm.cs @@ -169,5 +169,41 @@ namespace ActiveProtect.Utility return acceleration; } + + /// + /// 添加高斯噪声 + /// + /// 向量 + /// 添加高斯噪声后的向量 + public static Vector3D AddRandomPerturbation(Vector3D vector) + { + Random random = new(); + // 添加高斯噪声 + double sigma = 0.1; // 扰动标准差 + // 使用Box-Muller变换来生成高斯随机数 + double u1 = random.NextDouble(); // 生成[0, 1)之间的随机数 + double u2 = random.NextDouble(); // 生成[0, 1)之间的随机数 + double r = Math.Sqrt(-2.0 * Math.Log(u1)); + double theta = 2.0 * Math.PI * u2; + double gaussianX = r * Math.Cos(theta); + double gaussianY = r * Math.Sin(theta); + // 由于我们需要三个高斯随机数,我们将再次生成 + u1 = random.NextDouble(); // 生成[0, 1)之间的随机数 + u2 = random.NextDouble(); // 生成[0, 1)之间的随机数 + r = Math.Sqrt(-2.0 * Math.Log(u1)); + theta = 2.0 * Math.PI * u2; + double gaussianZ = r * Math.Cos(theta); + // 将高斯随机数转换为指定标准差的高斯随机数 + gaussianX *= sigma; + gaussianY *= sigma; + gaussianZ *= sigma; + return new Vector3D( + vector.X + gaussianX, + vector.Y + gaussianY, + vector.Z + gaussianZ + ); + } + + } }