From 4631841f5797e1eb60f6e53575c9ea4236a613b5 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Wed, 2 Apr 2025 12:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=BF=80=E5=85=89=E9=A9=BE?= =?UTF-8?q?=E6=9D=9F=E4=BB=AA=E7=9A=84=E5=88=B6=E5=AF=BC=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursor/rules/rule-claude-sonnet-37.mdc | 40 +++++++++++ .../data/missiles/laser_beam_rider/hj10.json | 4 +- .../Guidance/LaserBeamRiderGuidanceSystem.cs | 69 ++++++++++++++++--- ThreatSource/src/Indicator/LaserBeamRider.cs | 33 ++++++++- .../src/Simulation/SimulationEvents.cs | 16 +++++ 5 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 .cursor/rules/rule-claude-sonnet-37.mdc diff --git a/.cursor/rules/rule-claude-sonnet-37.mdc b/.cursor/rules/rule-claude-sonnet-37.mdc new file mode 100644 index 0000000..6b2ff0e --- /dev/null +++ b/.cursor/rules/rule-claude-sonnet-37.mdc @@ -0,0 +1,40 @@ +--- +description: Base Guidelines for Sonnet-3.7 + Cursor Agent +globs: *,**/* +alwaysApply: true +--- + +# prompts-claude-sonnet-37-rule-claude-sonnet-37.md + + +# --------------------------------------------------------------- +# DESCRIPTION: +# this rule helps to better control sonnet-3.7 + cursor. (like doing to much, creating unnecessary new files e.g.). +# especially the first two rules give the cursor agent already the most important instructions that worked for me. +# +# ❗ ATTENTION: +# 1. this does not work so easily for large codebases +# 2. remove everything from these rules that you do not need +# 3. also remove this comments +# --------------------------------------------------------------- + + +# Instructions + +1. Always use codebase_search with target_directories="{{ThreatSource/src}}" first to find existing core files +2. Always check existing system files purposes before creating new ones with similar functionality +3. Always list the cursor rules youre using + +# Optional + +- If a prompt or request specifies certain behaviors, languages, or output formats, you must obey them without deviation. +- Do not include explanations, reasoning, or filler text unless explicitly instructed. Stick strictly to the requested output. +- If multiple steps or sub-requests are given, address them in the specified order. Provide answers in the exact format or sequence requested. +- Pay close attention to all stated constraints (e.g., language choice, performance goals, coding style). Do not ignore any requirement or best practice stated. +- Only produce output relevant to the question or instructions. Do not add features, code, or details beyond what is explicitly asked. +- Deliver the response in a minimal yet complete form. Avoid unnecessary verbosity and tangential remarks. +- If the prompt requests a specific output format (e.g., a fenced code block, bullet points, JSON), follow that format exactly. +- If a prompt includes a pre-seeded answer structure (e.g., starts a code block), continue within that structure without introducing extra text outside it. +- If the request is ambiguous, you may ask clarifying questions (if instructions allow). Otherwise, state briefly that more information is needed. +- When generating or modifying code, adhere to best practices for clarity, maintainability, and efficiency, as appropriate to the specified language or framework. +- Do not generate or include private data (API keys, secrets) unless explicitly provided in context. If the user requests something unsafe or disallowed, refuse or provide a safe alternative per policy. diff --git a/ThreatSource/data/missiles/laser_beam_rider/hj10.json b/ThreatSource/data/missiles/laser_beam_rider/hj10.json index b7a8b2f..b47d6c6 100644 --- a/ThreatSource/data/missiles/laser_beam_rider/hj10.json +++ b/ThreatSource/data/missiles/laser_beam_rider/hj10.json @@ -27,8 +27,8 @@ } }, "LaserBeamRiderGuidanceConfig": { - "minDetectablePower": 1e-3, - "detectorDiameter": 0.1, + "minDetectablePower": 1e-10, + "detectorDiameter": 0.03, "controlFieldDiameter": 20.0, "proportionalGain": 30.0, "integralGain": 0.05, diff --git a/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs b/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs index c722f7a..415d7c2 100644 --- a/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs +++ b/ThreatSource/src/Guidance/LaserBeamRiderGuidanceSystem.cs @@ -51,9 +51,9 @@ namespace ThreatSource.Guidance /// /// 定义了探测器的灵敏度阈值 /// 低于此值时无法有效探测 - /// 典型值为1毫瓦 + /// 典型值为1e-10瓦 /// - private const double MinDetectablePower = 1e-3; + private const double MinDetectablePower = 1e-10; /// /// 探测器直径,单位:米 @@ -61,9 +61,9 @@ namespace ThreatSource.Guidance /// /// 定义了探测器的物理尺寸 /// 影响系统的接收能力 - /// 典型值为0.1米 + /// 典型值为0.03米 /// - private const double DetectorDiameter = 0.1; + private const double DetectorDiameter = 0.03; /// /// 控制场直径,单位:米 @@ -71,9 +71,9 @@ namespace ThreatSource.Guidance /// /// 定义了有效制导范围 /// 超出此范围将失去制导 - /// 典型值为20米 + /// 典型值为6米 /// - private const double ControlFieldDiameter = 20.0; + private const double ControlFieldDiameter = 6.0; /// /// 上一次的误差向量 @@ -93,6 +93,16 @@ namespace ThreatSource.Guidance /// public Vector3D LastGuidanceAcceleration { get; private set; } + /// + /// 偏航角偏差 + /// + public double YawAngleOffset { get; private set; } + + /// + /// 俯仰角偏差 + /// + public double PitchAngleOffset { get; private set; } + /// /// 积分误差向量 /// @@ -194,6 +204,9 @@ namespace ThreatSource.Guidance base.Activate(); // 在这里订阅事件,确保只订阅一次 SimulationManager.SubscribeToEvent(OnLaserJamming); + SimulationManager.SubscribeToEvent(OnLaserBeamStart); + SimulationManager.SubscribeToEvent(OnLaserBeamUpdate); + SimulationManager.SubscribeToEvent(OnLaserBeamStop); } /// @@ -204,6 +217,9 @@ namespace ThreatSource.Guidance base.Deactivate(); // 取消订阅事件 SimulationManager.UnsubscribeFromEvent(OnLaserJamming); + SimulationManager.UnsubscribeFromEvent(OnLaserBeamStart); + SimulationManager.UnsubscribeFromEvent(OnLaserBeamUpdate); + SimulationManager.UnsubscribeFromEvent(OnLaserBeamStop); } /// @@ -426,10 +442,13 @@ namespace ThreatSource.Guidance Debug.WriteLine($"激光驾束引导系统: 在控制场内, 距离: {shortestDistance}"); + // 计算导弹到激光源的距离 + Vector3D missileToSource = LaserSourcePosition - Position; + double distance = missileToSource.Magnitude(); + // 计算接收到的激光功率 - double beamArea = Math.PI * Math.Pow(config.ControlFieldDiameter / 2, 2); - double powerDensity = LaserPower / beamArea; - double receivedPower = powerDensity * (Math.PI * Math.Pow(config.DetectorDiameter / 2, 2)); + double receivedPower = CalculateReceivedLaserPower(distance); + Debug.WriteLine($"激光驾束引导系统: 接收到的激光功率: {receivedPower:E} W"); if(receivedPower >= config.MinDetectablePower) { @@ -442,6 +461,35 @@ namespace ThreatSource.Guidance } } + /// + /// 计算接收到的激光功率 + /// + /// 传播距离,单位:米 + /// 接收到的激光功率,单位:瓦特 + /// + /// 计算过程: + /// - 使用距离球面公式计算功率密度 + /// - 考虑探测器的有效接收面积 + /// - 可选:考虑大气衰减 + /// + private double CalculateReceivedLaserPower(double distance) + { + // 使用距离球面公式计算功率密度 + double powerDensity = LaserPower / (4 * Math.PI * Math.Pow(distance, 2)); + + // 计算探测器的有效接收面积 + double detectorArea = Math.PI * Math.Pow(config.DetectorDiameter / 2, 2); + + // 计算接收功率 + double receivedPower = powerDensity * detectorArea; + + // 考虑大气衰减(可选) + // double atmosphericTransmittance = Math.Exp(-attenuationCoefficient * distance); + // receivedPower *= atmosphericTransmittance; + + return receivedPower; + } + /// /// 计算制导加速度 /// @@ -670,6 +718,9 @@ namespace ThreatSource.Guidance // 更新激光波束参数 LaserPower = evt.BeamPower; + YawAngleOffset = evt.YawAngleOffset; + PitchAngleOffset = evt.PitchAngleOffset; + LaserIlluminationOn = true; HasGuidance = true; } diff --git a/ThreatSource/src/Indicator/LaserBeamRider.cs b/ThreatSource/src/Indicator/LaserBeamRider.cs index 4c396bb..1608a0d 100644 --- a/ThreatSource/src/Indicator/LaserBeamRider.cs +++ b/ThreatSource/src/Indicator/LaserBeamRider.cs @@ -171,7 +171,11 @@ namespace ThreatSource.Indicator Vector3D targetPosition = target.Position; LaserDirection = (targetPosition - Position).Normalize(); Debug.WriteLine($"激光驾束仪 {Id} 更新激光指向: {LaserDirection}"); - PublishLaserBeamUpdateEvent(); + if (MissileId != null && SimulationManager.GetEntityById(MissileId) is SimulationElement missile) + { + var (yawAngleOffset, pitchAngleOffset) = CalculateAngularDeviation(missile.Position); + PublishLaserBeamUpdateEvent(yawAngleOffset, pitchAngleOffset); + } } } } @@ -325,11 +329,13 @@ namespace ThreatSource.Indicator /// 通知仿真系统激光波束状态已更新 /// 包含最新的位置和方向信息 /// - private void PublishLaserBeamUpdateEvent() + private void PublishLaserBeamUpdateEvent(double yawAngleOffset, double pitchAngleOffset) { PublishEvent(new LaserBeamUpdateEvent { - LaserBeamRiderId = Id + LaserBeamRiderId = Id, + YawAngleOffset = yawAngleOffset, + PitchAngleOffset = pitchAngleOffset }); } @@ -434,5 +440,26 @@ namespace ThreatSource.Indicator } } } + + /// + /// 计算导弹相对于激光轴的角度偏差 + /// + /// 导弹位置 + /// (偏航角偏差, 俯仰角偏差),单位:弧度 + private (double yaw, double pitch) CalculateAngularDeviation(Vector3D missilePosition) + { + // 计算导弹相对于激光源的位置向量 + Vector3D relativePosition = missilePosition - Position; + Vector3D missileDirection = relativePosition.Normalize(); + + // 偏航角:XZ平面内的偏差(绕Y轴的旋转) + double yawAngle = Math.Atan2(missileDirection.X, missileDirection.Z) - + Math.Atan2(LaserDirection.X, LaserDirection.Z); + + // 俯仰角:与XZ平面的夹角(绕X轴的旋转) + double pitchAngle = Math.Asin(missileDirection.Y) - Math.Asin(LaserDirection.Y); + + return (yawAngle, pitchAngle); + } } } diff --git a/ThreatSource/src/Simulation/SimulationEvents.cs b/ThreatSource/src/Simulation/SimulationEvents.cs index de8f297..7b2183f 100644 --- a/ThreatSource/src/Simulation/SimulationEvents.cs +++ b/ThreatSource/src/Simulation/SimulationEvents.cs @@ -338,6 +338,22 @@ namespace ThreatSource.Simulation /// 用于抗干扰和安全识别 /// public LaserCodeConfig? LaserCodeConfig { get; set; } + + /// + /// 设置偏航角偏差 + /// + /// + /// 偏航角偏差 + /// + public double YawAngleOffset { get; set; } + + /// + /// 设置俯仰角偏差 + /// + /// + /// 俯仰角偏差 + /// + public double PitchAngleOffset { get; set; } } ///