diff --git a/Design.md b/Docs/Design.md similarity index 100% rename from Design.md rename to Docs/Design.md diff --git a/Docs/Seeker.md b/Docs/Seeker.md new file mode 100644 index 0000000..75816b7 --- /dev/null +++ b/Docs/Seeker.md @@ -0,0 +1,120 @@ +# 导引头仿真设计 + +## 1. 导引头类型 + + 导引头用于导弹的末端制导,包括激光、红外、毫米波等类型。 + +### 1.1 激光 + + 激光导引头,接收激光制导信号,一般用于激光半主动制导导弹。 + +### 1.2 红外 + + 红外导引头有红外和热成像两种,红外用于末敏弹,热成像用于红外热成像制导导弹。 + +### 1.3 毫米波雷达 + + 毫米波导引头,发射和接收毫米波信号,一般用于毫米波末制导导弹,也可用于末敏弹。 + +## 2. 导引头模型设计 + + 导引头模型设计包括导引头参数模型和导引头行为模型。 + +### 2.1 导引头参数模型 + + 导引头参数模型包括不同类型导引头的参数。 + +#### 2.1.1 激光导引头 + + 激光波长:1064nm + 激光编码:脉冲编码 + 激光频率:100Hz + 激光脉宽:10ns + 激光功率阈值:1e-6W + +#### 2.1.2 红外导引头 + + 红外波长:3-5um + 红外功率阈值:1e-6W + 红外频率:100Hz + 红外信噪比阈值:10dB + +#### 2.1.3 毫米波导引头 + + 毫米波波长:3mm + 毫米波频率:100Hz + 毫米波脉宽:10ns + 毫米波功率阈值:1e-6W + 毫米波信噪比阈值:10dB + +### 2.2 导引头行为模型 + + 导引头行为模型包括不同类型导引头的探测、识别、跟踪等行为。 + +#### 2.2.1 激光导引头 + + 1. 脉冲检测 + 2. 脉冲解码 + 3. 脉冲识别 + 4. 脉冲跟踪 + 5. 脉冲制导 + +#### 2.2.2 红外导引头 + + 1. 信号检测 + 2. 信号识别 + 3. 信号跟踪 + 4. 信号制导 + +#### 2.2.3 毫米波导引头 + + 1. 信号发射 + 2. 信号接收 + 3. 信号识别 + 4. 信号跟踪 + 5. 信号制导 + +## 3. 导引头设计思路 + +根据导引头的设计文档,我们可以提出以下设计思路: + +1. 基类设计: + 创建一个 `Seeker` 基类,包含所有导引头共有的属性和方法。 + +2. 子类实现: + 为每种类型的导引头(激光、红外、毫米波)创建继承自 `Seeker` 的子类。 + +3. 参数模型: + 在每个子类中实现特定类型导引头的参数模型,如波长、频率、功率阈值等。 + +4. 行为模型: + 为每个子类实现其特定的行为模型,如信号检测、识别、跟踪和制导。 + +5. 接口设计: + 定义通用接口,如 `IDetectable`、`ITrackable`,以统一不同类型导引头的行为。 + +6. 信号处理: + 实现信号处理逻辑,包括信号检测、解码、识别等。 + +7. 目标跟踪: + 实现目标跟踪算法,可以考虑使用卡尔曼滤波等方法。 + +8. 制导输出: + 设计制导输出接口,使导引头能够与导弹的制导系统集成。 + +9. 环境交互: + 考虑导引头与环境的交互,如大气衰减、干扰等因素的影响。 + +10. 性能模拟: + 实现导引头性能的模拟,如探测范围、角度精度等。 + +11. 配置系统: + 设计灵活的配置系统,允许在仿真中轻松调整导引头的参数。 + +12. 数据记录: + 实现数据记录功能,用于后续分析和可视化。 + +13. 测试框架: + 设计测试框架,以验证导引头模型的正确性和性能。 + +这个设计思路提供了一个全面的框架,涵盖了导引头模型的各个方面。实现时,我们可以逐步完善每个组件,确保模型的准确性和灵活性。这种设计也允许我们在未来轻松添加新类型的导引头或扩展现有导引头的功能。 diff --git a/Docs/TerminalSensitive.md b/Docs/TerminalSensitive.md new file mode 100644 index 0000000..a09659c --- /dev/null +++ b/Docs/TerminalSensitive.md @@ -0,0 +1,162 @@ +# 末敏弹仿真设计 + +## 1. 末敏弹的结构和原理 + +### 1.1 末敏弹的结构 + + 末敏弹是一种远程投放,顶部攻击目标的弹药,其结构包括母弹、子弹、战斗部、导引头。 + +### 1.2 末敏弹的制导系统 + + 末敏弹的制导系统包括毫米波雷达和红外两部分。 + +### 1.3 末敏弹的运行阶段 + + 末敏弹的运行阶段包括发射阶段、分离阶段、减速阶段、螺旋扫描阶段、攻击阶段、自毁阶段等。 + +## 2. 末敏弹的仿真 + +### 2.1 运动仿真 + + 运动仿真包括母弹和子弹的运行过程和运动规律,按运行阶段进行仿真。 + +### 2.2 导引头仿真 + + 导引头仿真包括导引头的工作原理、搜索、锁定、攻击过程。 + +## 3. 运动仿真 + +### 3.1 发射阶段 + + 行为:母弹发射 + 参数: + 发射位置:距离目标 20 公里 + 发射角度:俯仰角和方位角,需要根据目标的坐标计算,暂定 45 度 + 发射速度:1000 米/秒 + +### 3.2 分离阶段 + + 动作:子母弹分离 + 参数: + 分离高度:1000 米 + 分离距离:与目标水平距离 1000 米 + +### 3.3 减速阶段 + + 动作:开伞、减速减旋、稳态扫描 + 参数: + 减速高度:400 米 + 减速距离:与目标水平距离 300 米 + +### 3.4 螺旋扫描阶段 + + 动作:螺旋扫描 + 参数: + 扫描高度:200 米 + 扫描距离:与目标水平距离小于 100 米 + 扫描角度:30 度 + 扫描线视场角:15 度 + 扫描速度:2 圈/秒 + 下降速度:10 米/秒 + +### 3.5 攻击阶段 + + 动作:攻击目标 + 参数: + 攻击高度:小于 200 米,扫描发现目标之后的 0.5 秒 + 攻击距离:与目标水平距离小于 100 米 + 攻击速度:2000 米/秒 + +### 3.6 自毁阶段 + + 动作:自毁 + 参数: + 自毁高度:20 米 + 自毁条件:扫描未发现目标 + +## 4. 导引头仿真 + +### 4.1 毫米波雷达 + + 毫米波雷达的仿真包括雷达的参数模型和行为模型。 + +#### 4.1.1 参数模型 + + 波长:3毫米 + 频率:94GHz + 脉冲宽度:100ns + 脉冲重复频率:10kHz + 天线增益:30dB + 噪声系数:5dB + 信噪比阈值:100dB + +#### 4.1.2 行为模型 + + 测高:到达 20 米,发出自毁信号 + +### 4.2 红外导引头 + + 红外导引头的仿真包括红外导引头的参数模型和行为模型。 + +#### 4.2.1 参数模型 + + 波长:3-5 微米 + 模数:单模、多模 + 信噪比阈值:100dB + +#### 4.2.2 行为模型 + + 探测目标:探测到目标,发出攻击信号 + +## 5. 干扰方式 + + 干扰方式包括烟幕干扰、毫米波补偿 + +### 5.1 烟幕干扰 + + 坦克顶部烟幕弹装置,发射烟幕弹,形成烟幕,干扰毫米波雷达和红外导引头。 + +### 5.2 毫米波补偿 + + 坦克顶部毫米波干扰机,发射毫米波补偿信号,干扰末敏弹毫米波雷达。 + +## 6. 仿真模型设计思路 + +基于上述末敏弹的仿真设计,我们可以设计一个末敏弹仿真模型,主要思路如下: + +1. 类结构设计: + - 创建一个 `TerminalSensitiveMissile` 类,继承自 `MissileBase`。 + - 创建 `MillimeterWaveRadar` 和 `InfraredSeeker` 类来模拟导引头。 + +2. 飞行阶段管理: + - 定义一个枚举 `TerminalSensitiveStage` 来表示末敏弹的不同飞行阶段。 + - 实现一个状态机来管理这些阶段的转换。 + +3. 运动模型: + - 为每个飞行阶段实现特定的运动模型。 + - 使用物理公式计算弹道,考虑重力、空气阻力等因素。 + +4. 导引头模拟: + - 实现毫米波雷达和红外导引头的探测逻辑。 + - 模拟信号处理、目标识别和跟踪。 + +5. 目标交互: + - 实现与目标(如坦克)的交互逻辑。 + - 模拟目标探测、锁定和攻击过程。 + +6. 环境交互: + - 考虑环境因素对末敏弹性能的影响,如天气条件。 + +7. 干扰模拟: + - 实现烟幕干扰和毫米波补偿等干扰方式的影响。 + +8. 参数配置: + - 设计一个灵活的参数配置系统,允许调整各种性能参数。 + +9. 数据记录和分析: + - 实现数据记录功能,用于后续分析和可视化。 + +10. 集成到仿真系统: + - 确保末敏弹模型能够与整个仿真系统无缝集成。 + +这个设计应该能够全面模拟末敏弹的行为,包括其复杂的飞行阶段和导引系统。实现时,我们需要逐步完善每个组件,并进行充分的测试和调整。 diff --git a/Models/LaserBeamRider.cs b/Models/LaserBeamRider.cs index 6bb77cd..ce4cf9a 100644 --- a/Models/LaserBeamRider.cs +++ b/Models/LaserBeamRider.cs @@ -29,8 +29,8 @@ namespace ActiveProtect.Models // 目标 public string TargetId { get; private set; } - public LaserBeamRider(string id, string missileId, string targetId, LaserBeamRiderConfig config, ISimulationManager simulationManager) - : base(id, config.InitialPosition, new Orientation(0, 0, 0), simulationManager) + public LaserBeamRider(string id, string missileId, string targetId, double speed, LaserBeamRiderConfig config, ISimulationManager simulationManager) + : base(id, config.InitialPosition, new Orientation(0, 0, 0), speed, simulationManager) { LaserPower = config.LaserPower; ControlFieldDiameter = config.ControlFieldDiameter; diff --git a/Models/LaserDesignator.cs b/Models/LaserDesignator.cs index b6b583e..7cfea86 100644 --- a/Models/LaserDesignator.cs +++ b/Models/LaserDesignator.cs @@ -52,8 +52,8 @@ namespace ActiveProtect.Models /// 导弹ID /// 激光指示器配置 /// 仿真管理器 - public LaserDesignator(string id, string targetId, string missileId, LaserDesignatorConfig config, ISimulationManager simulationManager) - : base(id, config.InitialPosition, new Orientation(), simulationManager) + public LaserDesignator(string id, string targetId, string missileId, double speed, LaserDesignatorConfig config, ISimulationManager simulationManager) + : base(id, config.InitialPosition, new Orientation(), speed, simulationManager) { TargetId = targetId; MissileId = missileId; diff --git a/Models/LaserJammer.cs b/Models/LaserJammer.cs index 89ebe1d..c92edaf 100644 --- a/Models/LaserJammer.cs +++ b/Models/LaserJammer.cs @@ -58,7 +58,7 @@ namespace ActiveProtect.Models /// 被监视实体的ID /// 激光干扰器配置 public LaserJammer(string id, Vector3D position, Orientation orientation, ISimulationManager simulationManager, string monitoredEntityId, LaserJammerConfig config) - : base(id, position, orientation, simulationManager) + : base(id, position, orientation, 0, simulationManager) { MonitoredEntityId = monitoredEntityId; IsJamming = false; diff --git a/Models/LaserWarner.cs b/Models/LaserWarner.cs index 04b1082..2582e4f 100644 --- a/Models/LaserWarner.cs +++ b/Models/LaserWarner.cs @@ -38,7 +38,7 @@ namespace ActiveProtect.Models /// 被监视实体的ID /// 激光告警器配置 public LaserWarner(string id, Vector3D position, Orientation orientation, ISimulationManager simulationManager, string monitoredEntityId, LaserWarnerConfig config) - : base(id, position, orientation, simulationManager) + : base(id, position, orientation, 0, simulationManager) { MonitoredEntityId = monitoredEntityId; IsAlarming = false; diff --git a/Models/MissileBase.cs b/Models/MissileBase.cs index 5ba575e..3bd8f20 100644 --- a/Models/MissileBase.cs +++ b/Models/MissileBase.cs @@ -98,7 +98,7 @@ namespace ActiveProtect.Models /// /// 最大加速度(米/秒²) /// - public double MaxAcceleration { get; protected set; } = 100; + public double MaxAcceleration { get; protected set; } = 10000; /// /// 比例导引系数 @@ -142,7 +142,7 @@ namespace ActiveProtect.Models /// 构造函数 /// public MissileBase(string id, MissileConfig missileConfig, ISimulationManager simulationManager) - : base(id, missileConfig.InitialPosition, missileConfig.InitialOrientation, simulationManager) + : base(id, missileConfig.InitialPosition, missileConfig.InitialOrientation, missileConfig.InitialSpeed, simulationManager) { // 初始化导弹属性 Speed = missileConfig.InitialSpeed; @@ -161,8 +161,6 @@ namespace ActiveProtect.Models MaxAcceleration = missileConfig.MaxAcceleration; ProportionalNavigationCoefficient = missileConfig.ProportionalNavigationCoefficient; TargetId = $"Tank_{missileConfig.TargetIndex + 1}"; - Vector3D horizontalDirection = new Vector3D(Orientation.ToVector().X, 0, Orientation.ToVector().Z).Normalize(); - Velocity = horizontalDirection * missileConfig.InitialSpeed; // 初始化策略字典 stageStrategies = new Dictionary @@ -179,7 +177,7 @@ namespace ActiveProtect.Models currentStage = stageStrategies[CurrentStage]; - LastTargetPosition = Position; + LastTargetPosition = Vector3D.Zero; DistanceToTarget = Vector3D.Distance(Position, SimulationManager.GetEntityById(TargetId).Position); } @@ -231,8 +229,9 @@ namespace ActiveProtect.Models throw new NotImplementedException(); } - private void UpdateMotionState(double deltaTime, Vector3D guidanceCommand) + protected virtual void UpdateMotionState(double deltaTime, Vector3D guidanceCommand) { + Vector3D acceleration = CalculateAcceleration(Velocity, guidanceCommand); // 使用四阶龙格-库塔方法更新导弹的位置和速度 @@ -378,67 +377,6 @@ namespace ActiveProtect.Models SelfDestruct(); } - /// - /// 计算导弹的加速度 - /// - // private (Vector3D, Vector3D) CalculateDerivatives_RK4(Vector3D position, Vector3D velocity, double deltaTime) - // { - // Vector3D guidanceAcceleration = Vector3D.Zero; - // Vector3D thrustAcceleration = Vector3D.Zero; - - // switch (CurrentStage) - // { - // case FlightStage.Launch: - // thrustAcceleration = Orientation.ToVector() * ThrustAcceleration; - // break; - // case FlightStage.Acceleration: - // thrustAcceleration = Orientation.ToVector() * ThrustAcceleration; - // guidanceAcceleration = CalculateProportionalNavigation(position); - // break; - // case FlightStage.Cruise: - // thrustAcceleration = Orientation.ToVector() * (ThrustAcceleration * 0.1); - // guidanceAcceleration = CalculateProportionalNavigation(position) * 0.5; - // break; - // case FlightStage.TerminalGuidance: - // thrustAcceleration = Orientation.ToVector() * (ThrustAcceleration * 0.1); - // guidanceAcceleration = CalculateProportionalNavigation(position) * 1.5; - // break; - // case FlightStage.Attack: - // thrustAcceleration = Orientation.ToVector() * ThrustAcceleration; - // guidanceAcceleration = CalculateProportionalNavigation(position) * 2; - // break; - // } - - // if (!HasGuidance) - // { - // guidanceAcceleration = Vector3D.Zero; - // if (velocity.Magnitude() > 0) - // { - // thrustAcceleration = velocity.Normalize() * ThrustAcceleration; - // } - // else - // { - // thrustAcceleration = Orientation.ToVector() * ThrustAcceleration; - // } - // } - - // // 计算空气阻力的影响 - // Vector3D dragAcceleration = velocity.Normalize() * -1 * CalculateDrag(velocity.Magnitude()) / Mass; - - // // 计算重力加速度(反坦克导弹一般升力很小, 主要依靠初始发射动能和持续的推力来维持飞行) - // //Vector3D gravityCompensation = new(0, 9.81, 0); - // Vector3D gravityAcceleration = new(0, -9.81, 0); - - // Vector3D totalAcceleration = guidanceAcceleration + thrustAcceleration + gravityAcceleration + dragAcceleration; - - // if (totalAcceleration.Magnitude() > MaxAcceleration) - // { - // totalAcceleration = totalAcceleration.Normalize() * MaxAcceleration; - // } - - // return (velocity, totalAcceleration); - // } - /// /// 计算空气阻力 /// @@ -552,6 +490,8 @@ namespace ActiveProtect.Models return $"导弹 {missileRunningState.Id}:\n" + $" 位置: {missileRunningState.Position}\n" + $" 速度: {missileRunningState.Speed:F2} m/s\n" + + $" 速度分量: {missileRunningState.Velocity}\n" + + $" 朝向: {missileRunningState.Orientation}\n" + $" 当前状态: {missileRunningState.CurrentStage}\n" + $" 飞行时间: {missileRunningState.FlightTime:F2}/{MaxFlightTime:F2}\n" + $" 飞行距离: {missileRunningState.FlightDistance:F2}/{MaxFlightDistance:F2}\n" + diff --git a/Models/Tank.cs b/Models/Tank.cs index 71ff327..36ebb01 100644 --- a/Models/Tank.cs +++ b/Models/Tank.cs @@ -35,7 +35,7 @@ namespace ActiveProtect.Models /// 坦克配置 /// 仿真管理器 public Tank(string id, TankConfig tankConfig, ISimulationManager simulationManager) - : base(id, tankConfig.InitialPosition, tankConfig.InitialOrientation, simulationManager) + : base(id, tankConfig.InitialPosition, tankConfig.InitialOrientation, tankConfig.InitialSpeed, simulationManager) { Speed = tankConfig.InitialSpeed; MaxSpeed = tankConfig.MaxSpeed; diff --git a/Models/TerminalSensitiveMissile.cs b/Models/TerminalSensitiveMissile.cs new file mode 100644 index 0000000..f52fc21 --- /dev/null +++ b/Models/TerminalSensitiveMissile.cs @@ -0,0 +1,321 @@ +using System; +using System.Collections.Generic; +using ActiveProtect.SimulationEnvironment; + +namespace ActiveProtect.Models +{ + public class TerminalSensitiveMissile : MissileBase + { + private enum TerminalSensitiveStage + { + Launch, // 发射阶段 + Separation, // 分离阶段 + Deceleration, // 减速阶段 + SpiralScan, // 螺旋扫描阶段 + Attack, // 攻击阶段 + SelfDestruct // 自毁阶段 + } + + private TerminalSensitiveStage currentWorkingStage; + private Dictionary> stageStrategies; + + private double spiralAngle; + private const double SpiralRotationSpeed = 4 * Math.PI; // 2 rotations per second + private const double VerticalDescentSpeed = 10; // 10 m/s + private const double ScanAngle = 30 * Math.PI / 180; // 30 degrees in radians + + // 分离距离 1000米 + private const double SeparationDistance = 1000; + + // 分离高度 1000米 + private const double SeparationHeight = 1000; + + // 减速高度 400米 + private const double DecelerationHeight = 400; + + // 扫描高度 200米 + private const double ScanningHeight = 200; + + // 自毁高度 20米 + private const double SelfDestructHeight = 20; + + private Vector3D lastScanDirection; + private bool targetDetected; + private double detectionAngle; + + //目标位置 + private Vector3D TargetPosition; + + //末敏弹子母弹分离位置 + private Vector3D SeparationPosition; + + public Vector3D GuidanceCommand { get; private set; } + + public TerminalSensitiveMissile(string id, MissileConfig missileConfig, string targetId, ISimulationManager simulationManager) + : base(id, missileConfig, simulationManager) + { + spiralAngle = 0; + lastScanDirection = Vector3D.Zero; + targetDetected = false; + detectionAngle = 0; + GuidanceCommand = Vector3D.Zero; + + TargetPosition = SimulationManager.GetEntityById(targetId).Position; + + SeparationPosition = CalculatePointOnTrajectory(Position, TargetPosition, SeparationDistance, SeparationHeight); + + // 初始化策略字典 + stageStrategies = new Dictionary> + { + { TerminalSensitiveStage.Launch, UpdateLaunchStage }, + { TerminalSensitiveStage.Separation, UpdateSeparationStage }, + { TerminalSensitiveStage.Deceleration, UpdateDecelerationStage }, + { TerminalSensitiveStage.SpiralScan, UpdateSpiralScanStage }, + { TerminalSensitiveStage.Attack, UpdateAttackStage }, + { TerminalSensitiveStage.SelfDestruct, UpdateSelfDestructStage } + }; + + currentWorkingStage = TerminalSensitiveStage.Launch; + } + + public override void Update(double deltaTime) + { + //base.Update(deltaTime); + if (!IsActive) return; + + if (ShouldSelfDestruct()) + { + SelfDestruct(); + return; + } + + Console.WriteLine($"末敏弹 {Id} 当前位置: {Position}"); + Console.WriteLine($"末敏弹 {Id} 分离位置: {SeparationPosition}"); + + // 使用当前阶段的策略更新导弹状态 + if (stageStrategies.TryGetValue(currentWorkingStage, out var updateStrategy)) + { + updateStrategy(deltaTime); + } + + } + + private void UpdateLaunchStage(double deltaTime) + { + // 无动力抛物线飞行 + ApplyGravity(deltaTime); + + base.UpdateMotionState(deltaTime, GuidanceCommand); + + if (Vector3D.Distance(Position, SeparationPosition) <= 200) + { + currentWorkingStage = TerminalSensitiveStage.Separation; + } + } + + private void UpdateSeparationStage(double deltaTime) + { + // 子母弹分离逻辑 + // 这里可以添加分离的具体实现,比如创建子弹等 + Console.WriteLine($"末敏弹 {Id} 进入分离"); + + switch(Velocity.Magnitude()) + { + case >= 200: + GuidanceCommand = new Vector3D(400, -400, 0); + break; + case >= 100: + GuidanceCommand = new Vector3D(30, -30, 0); + break; + case >= 50: + GuidanceCommand = new Vector3D(20, -20, 0); + break; + case >= 20: + GuidanceCommand = new Vector3D(5, -10, 0); + break; + default: + GuidanceCommand = new Vector3D(0, -10, 0); + break; + } + base.UpdateMotionState(deltaTime, GuidanceCommand); + + if (Position.Y <= DecelerationHeight) + { + currentWorkingStage = TerminalSensitiveStage.Deceleration; + } + } + + private void UpdateDecelerationStage(double deltaTime) + { + Console.WriteLine($"末敏弹 {Id} 进入减速"); + // 减速下降 + Velocity = new Vector3D(0, -VerticalDescentSpeed, 0); + Position += Velocity * deltaTime; + + if (Position.Y <= ScanningHeight) + { + currentWorkingStage = TerminalSensitiveStage.SpiralScan; + } + } + + private void UpdateSpiralScanStage(double deltaTime) + { + Console.WriteLine($"末敏弹 {Id} 进入螺旋扫描"); + + spiralAngle += SpiralRotationSpeed * deltaTime; + + // 计算水平速度分量 + double horizontalSpeed = VerticalDescentSpeed * Math.Tan(ScanAngle); + Vector3D horizontalVelocity = new Vector3D( + Math.Cos(spiralAngle) * horizontalSpeed, + 0, + Math.Sin(spiralAngle) * horizontalSpeed + ); + + // 更新速度 + Velocity = new Vector3D(horizontalVelocity.X, -VerticalDescentSpeed, horizontalVelocity.Z); + + // 计算扫描方向 + Vector3D scanDirection = new Vector3D( + Math.Cos(spiralAngle) * Math.Sin(ScanAngle), + -Math.Cos(ScanAngle), + Math.Sin(spiralAngle) * Math.Sin(ScanAngle) + ); + + if (DetectTarget(scanDirection)) + { + if (!targetDetected) + { + targetDetected = true; + detectionAngle = spiralAngle; + } + else if (Math.Abs(spiralAngle - detectionAngle) < 0.1) // 允许一定的误差 + { + currentWorkingStage = TerminalSensitiveStage.Attack; + } + } + + lastScanDirection = scanDirection; + + if (Position.Y <= SelfDestructHeight) + { + currentWorkingStage = TerminalSensitiveStage.SelfDestruct; + } + } + + private void UpdateAttackStage(double deltaTime) + { + // 攻击逻辑 + Vector3D targetPosition = SimulationManager.GetEntityById(TargetId).Position; + Vector3D direction = (targetPosition - Position).Normalize(); + Velocity = direction * MaxSpeed; + + if (Vector3D.Distance(Position, targetPosition) < 1) + { + Explode(); + } + } + + private void UpdateSelfDestructStage(double deltaTime) + { + // 实现自毁逻辑 + Explode(); + } + + private bool DetectTarget(Vector3D scanDirection) + { + Vector3D targetPosition = SimulationManager.GetEntityById(TargetId).Position; + Vector3D toTarget = (targetPosition - Position).Normalize(); + + // 检查目标是否在扫描线上 + return Vector3D.DotProduct(scanDirection, toTarget) > Math.Cos(0.5 * Math.PI / 180); // 允许0.5度的误差 + } + + private void ApplyGravity(double deltaTime) + { + GuidanceCommand = new Vector3D(0, -9.81, 0); + } + + public override string GetStatus() + { + string baseStatus = base.GetStatus().Replace("导弹", "末敏弹"); + string additionalStatus = $"\n 扫描阶段: {(currentWorkingStage == TerminalSensitiveStage.SpiralScan ? "有效" : "无效")} \n"; + return baseStatus + additionalStatus; + } + + public override void Activate() + { + base.Activate(); + // SimulationManager.SubscribeToEvent(OnLaserBeamStart); + // SimulationManager.SubscribeToEvent(OnLaserBeamStop); + // SimulationManager.SubscribeToEvent(OnLaserBeamUpdate); + } + + public override void Deactivate() + { + base.Deactivate(); + // SimulationManager.UnsubscribeFromEvent(OnLaserBeamStart); + // SimulationManager.UnsubscribeFromEvent(OnLaserBeamStop); + // SimulationManager.UnsubscribeFromEvent(OnLaserBeamUpdate); + } + + public static (double angle, double distance) CalculateLaunchParameters(double initialVelocity, double targetHeight, double targetDistance) + { + double g = 9.8; // 重力加速度 + double v = initialVelocity; + double y = targetHeight; + double x = targetDistance; + + // 计算发射角度(弧度) + double angle = Math.Atan((v * v + Math.Sqrt(Math.Pow(v, 4) - g * (g * x * x + 2 * y * v * v))) / (g * x)); + + // 计算水平飞行距离 + double t = x / (v * Math.Cos(angle)); + double totalDistance = v * Math.Cos(angle) * t; + + return (angle, totalDistance); + } + + public static Vector3D CalculateLaunchPosition(Vector3D knownPoint, Vector3D velocity) + { + double g = 9.8; // 重力加速度 + double x = knownPoint.X; + double y = knownPoint.Y; + double vx = velocity.X; + double vy = velocity.Y; + + // 计算时间 t + double t = (-vy - Math.Sqrt(vy * vy + 2 * g * y)) / -g; + + // 计算发射点的 x 坐标 + double launchX = x - vx * t; + + // 发射点的 y 和 z 坐标为 0 + return new Vector3D(launchX, 0, 0); + } + + public static Vector3D CalculatePointOnTrajectory(Vector3D launchPosition, Vector3D targetPosition, double distanceFromTarget, double height) + { + // 确保发射位置和目标位置的y坐标为0 + launchPosition = new Vector3D(launchPosition.X, 0, launchPosition.Z); + targetPosition = new Vector3D(targetPosition.X, 0, targetPosition.Z); + + // 计算发射方向向量 + Vector3D direction = targetPosition - launchPosition; + + // 计算总距离 + double totalDistance = direction.Magnitude(); + + // 归一化方向向量 + direction = direction.Normalize(); + + // 计算所需点的位置 + Vector3D pointOnTrajectory = targetPosition - direction * distanceFromTarget; + + // 返回结果,y坐标设置为指定的高度 + return new Vector3D(pointOnTrajectory.X, height, pointOnTrajectory.Z); + } + + + } +} diff --git a/Program.cs b/Program.cs index 61817a7..346b215 100644 --- a/Program.cs +++ b/Program.cs @@ -28,7 +28,7 @@ namespace ActiveProtect theta_m = -0.1, vm = 0 }; - + // 创建仿真配置 var config = new SimulationConfig { @@ -83,7 +83,7 @@ namespace ActiveProtect InitialSpeed = 700, MaxSpeed = 800, TargetIndex = 0, - MaxFlightTime = 0.05, + MaxFlightTime = 0, MaxFlightDistance = 5000, ThrustAcceleration = 50, MaxEngineBurnTime = 10, @@ -102,7 +102,7 @@ namespace ActiveProtect InitialSpeed = 300, MaxSpeed = 400, TargetIndex = 0, - MaxFlightTime = 0.05, + MaxFlightTime = 0, MaxFlightDistance = 3000, ThrustAcceleration = 50, MaxEngineBurnTime = 10, @@ -112,10 +112,29 @@ namespace ActiveProtect DistanceParams = new MissileDistanceParams(500, 200, 10), Mass = 50, Type = MissileType.LaserBeamRiderGuidance + }, + // 末敏弹配置 + new MissileConfig + { + InitialPosition = new Vector3D(3500, 0, 100), // 发射位置 + InitialOrientation = new Orientation(Math.PI, Math.PI/8, 0), // 使用计算得到的发射角度 + InitialSpeed = 800, + MaxSpeed = 1000, + TargetIndex = 0, + MaxFlightTime = 10, // 增加最大飞行时间 + MaxFlightDistance = 5000, // 增加最大飞行距离 + ThrustAcceleration = 0, // 无推力加速度 + MaxEngineBurnTime = 0, // 无发动机燃烧时间 + MaxAcceleration = 1000, + ProportionalNavigationCoefficient = 3, + StageConfig = FlightStageConfig.StandardMissile, + DistanceParams = new MissileDistanceParams(1000, 400, 20), + Mass = 100, + Type = MissileType.TerminalSensitiveMissile } }, - SimulationTimeStep = 0.025 + SimulationTimeStep = 0.05 }; // 创建仿真管理器 diff --git a/SimulationEnvironment/SimulationConfig.cs b/SimulationEnvironment/SimulationConfig.cs index 57061b0..cf44f70 100644 --- a/SimulationEnvironment/SimulationConfig.cs +++ b/SimulationEnvironment/SimulationConfig.cs @@ -320,7 +320,8 @@ namespace ActiveProtect.SimulationEnvironment LaserBeamRiderGuidance, // 激光驾束制导 InfraredCommandGuidance, // 红外指令制导 InfraredImagingTerminalGuidance, // 红外成像末制导 - MillimeterWaveTerminalGuidance // 毫米波末制导 + MillimeterWaveTerminalGuidance, // 毫米波末制导 + TerminalSensitiveMissile // 末敏弹 } /// @@ -379,7 +380,7 @@ namespace ActiveProtect.SimulationEnvironment /// /// 标准导弹的预设配置, 所有阶段都启用 /// - public static FlightStageConfig StandardMissile => new(true, true, true, true, true); + public static FlightStageConfig StandardMissile => new(false, true, false, false, false); /// /// 激光半主动制导导弹的预设配置, 没有加速阶段 diff --git a/SimulationEnvironment/SimulationElement.cs b/SimulationEnvironment/SimulationElement.cs index 8323d37..ab834a7 100644 --- a/SimulationEnvironment/SimulationElement.cs +++ b/SimulationEnvironment/SimulationElement.cs @@ -1,3 +1,4 @@ +using System; using ActiveProtect.Models; namespace ActiveProtect.SimulationEnvironment @@ -44,13 +45,13 @@ namespace ActiveProtect.SimulationEnvironment /// 初始位置 /// 初始朝向 /// 仿真管理器 - protected SimulationElement(string id, Vector3D position, Orientation orientation, ISimulationManager simulationManager) + protected SimulationElement(string id, Vector3D position, Orientation orientation, double speed, ISimulationManager simulationManager) { Id = id; Position = position; Orientation = orientation; + Velocity = orientation.ToVector() * speed; SimulationManager = simulationManager; - Velocity = Vector3D.Zero; IsActive = true; } diff --git a/SimulationEnvironment/SimulationManager.cs b/SimulationEnvironment/SimulationManager.cs index b35a6f9..ca0ae94 100644 --- a/SimulationEnvironment/SimulationManager.cs +++ b/SimulationEnvironment/SimulationManager.cs @@ -134,34 +134,24 @@ namespace ActiveProtect.SimulationEnvironment for (int i = 0; i < config.MissileConfigs.Count; i++) { var missileConfig = config.MissileConfigs[i]; - - // 确保 MaxFlightTime 设置合理 - if (missileConfig.MaxFlightTime <= 0) + MissileBase missile; + + switch (missileConfig.Type) { - missileConfig.MaxFlightTime = 300; // 设置一个默认值,比如 300 秒 - Console.WriteLine($"警告:导弹配置 {i} 的 MaxFlightTime 无效,已设置为默认值 300 秒"); + case MissileType.LaserSemiActiveGuidance: + missile = new LaserSemiActiveGuidedMissile($"LSGM_{i + 1}", missileConfig, "Tank_1", this); + break; + case MissileType.LaserBeamRiderGuidance: + missile = new LaserBeamRiderMissile($"LBRM_{i + 1}", "LBR_1", missileConfig, this); + break; + case MissileType.TerminalSensitiveMissile: + missile = new TerminalSensitiveMissile($"TSM_{i + 1}", missileConfig, "Tank_1", this); + break; + default: + missile = new MissileBase($"M_{i + 1}", missileConfig, this); + break; } - MissileBase missile = missileConfig.Type switch - { - MissileType.LaserSemiActiveGuidance => new LaserSemiActiveGuidedMissile( - $"LSGM_{i + 1}", - missileConfig, - "LD_1", - this - ), - MissileType.LaserBeamRiderGuidance => new LaserBeamRiderMissile( - $"LBRM_{i + 1}", - "Tank_1", - missileConfig, - this - ), - _ => new MissileBase( - $"NM_{i + 1}", - missileConfig, - this - ), - }; Elements.Add(missile); } @@ -171,6 +161,7 @@ namespace ActiveProtect.SimulationEnvironment $"LD_1", "Tank_1", "LSGM_1", + 0, laserDesignatorConfig, this ); @@ -182,6 +173,7 @@ namespace ActiveProtect.SimulationEnvironment "LBR_1", "LBRM_2", "Tank_1", + 0, laserBeamRiderConfig, this );