76 lines
4.6 KiB
Markdown
76 lines
4.6 KiB
Markdown
# 上下文
|
||
文件名:[missile_lift_model.md]
|
||
创建于:[2024-05-23T10:00:00Z]
|
||
创建者:[AI]
|
||
|
||
# 任务描述
|
||
用户请求设计并实现导弹的升力加速度模型。
|
||
升力加速度az =(功角a - 5 度)* 1 米每秒的平方。
|
||
功角 a 的范围是大于等于负 5 度且小于等于 15 度。在其他情况下,az=0。
|
||
功角 a 定义为导弹速度矢量与XY平面(水平面)的夹角。
|
||
升力加速度作用在导弹的垂直方向(垂直于速度矢量,并在由速度矢量和世界Y轴定义的平面内)。
|
||
|
||
# 项目概述
|
||
项目为一个导弹仿真系统,需要修改导弹基类及其运动算法来集成新的升力模型。
|
||
|
||
---
|
||
*以下部分由 AI 在协议执行过程中维护*
|
||
---
|
||
|
||
# 分析 (由 RESEARCH 模式填充)
|
||
- 升力计算的核心位置在 `BaseMissile.cs` 的 `CalculateAcceleration` 方法。
|
||
- 攻角 (alpha) 用户定义为速度矢量与水平面 (XZ平面,假设Y为垂直轴) 的夹角。
|
||
- 升力方向垂直于速度矢量,并位于由速度矢量和世界Y轴(`Vector3D.UnitY`)定义的平面内。
|
||
- `MotionAlgorithm.cs` 是存放运动相关计算的工具类。
|
||
|
||
# 提议的解决方案 (由 INNOVATE 模式填充)
|
||
方案:在 `MotionAlgorithm.cs` 中增加计算攻角和升力矢量的方法。在 `BaseMissile.cs` 中调用这些方法并将升力加入总加速度。
|
||
|
||
# 实施计划 (由 PLAN 模式生成)
|
||
见下方实施检查清单。
|
||
|
||
实施检查清单:
|
||
1. **在 `ThreatSource/src/Utils/MotionAlgorithm.cs` 中**:
|
||
1. 创建 `public static double CalculateAngleOfAttackFromHorizontal(Vector3D velocity)` 方法。
|
||
* 输入: `Vector3D velocity`。
|
||
* 计算水平速度大小 `horizontalMagnitude = Math.Sqrt(velocity.X * velocity.X + velocity.Z * velocity.Z)`。
|
||
* 处理 `horizontalMagnitude < 1e-6` 的情况:
|
||
* If `velocity.Y > 0`, return `Math.PI / 2`.
|
||
* If `velocity.Y < 0`, return `-Math.PI / 2`.
|
||
* Else, return `0.0`.
|
||
* 否则,计算 `alpha_rad = Math.Atan2(velocity.Y, horizontalMagnitude)`。
|
||
* Return `alpha_rad`.
|
||
2. **在 `ThreatSource/src/Utils/MotionAlgorithm.cs` 中**:
|
||
1. 创建 `public static Vector3D CalculateLiftAccelerationVector(Vector3D velocity, double angleOfAttackDegrees)` 方法。
|
||
* 输入: `Vector3D velocity`, `double angleOfAttackDegrees`.
|
||
* 定义常量: `MIN_AOA_DEG = -5.0`, `MAX_AOA_DEG = 15.0`, `AOA_OFFSET_DEG = 5.0`.
|
||
* 计算 `az_magnitude`:
|
||
* If `angleOfAttackDegrees >= MIN_AOA_DEG && angleOfAttackDegrees <= MAX_AOA_DEG`:
|
||
* `az_magnitude = (angleOfAttackDegrees - AOA_OFFSET_DEG) * 1.0`.
|
||
* Else:
|
||
* `az_magnitude = 0.0`.
|
||
* If `Math.Abs(az_magnitude) < 1e-6 || velocity.MagnitudeSquared() < 1e-9`, return `Vector3D.Zero`.
|
||
* 定义 `WorldUp = Vector3D.UnitY`.
|
||
* `velocityNormalized = velocity.Normalize()`.
|
||
* `RightVec = Vector3D.CrossProduct(velocityNormalized, WorldUp)`.
|
||
* If `RightVec.MagnitudeSquared() < 1e-9`, return `Vector3D.Zero` (处理垂直飞行情况).
|
||
* `LiftDir = Vector3D.CrossProduct(RightVec, velocityNormalized).Normalize()`.
|
||
* `liftAcceleration = LiftDir * az_magnitude`.
|
||
* Return `liftAcceleration`.
|
||
3. **在 `ThreatSource/src/Missile/BaseMissile.cs` 的 `CalculateAcceleration(Vector3D velocity)` 方法中**:
|
||
1. 在计算 `totalAcceleration` 之前,获取当前速度 `currentMissileVelocity = velocity` (或直接用 `velocity` 参数)。
|
||
2. 计算攻角(度): `double currentAoARad = MotionAlgorithm.CalculateAngleOfAttackFromHorizontal(currentMissileVelocity);`
|
||
3. `double currentAoADegrees = currentAoARad * 180.0 / Math.PI;`
|
||
4. 计算升力加速度矢量: `Vector3D liftAcceleration = MotionAlgorithm.CalculateLiftAccelerationVector(currentMissileVelocity, currentAoADegrees);`
|
||
5. 修改 `totalAcceleration` 的计算公式,加入 `liftAcceleration`:
|
||
`Vector3D totalAcceleration = GuidanceAcceleration + ThrustAcceleration + dragAcceleration + GravityAcceleration + liftAcceleration;`
|
||
6. 更新 `Debug.WriteLine` 语句,包含 `liftAcceleration` 的值。例如,在原有的基础上追加 `$", 升力: {liftAcceleration}"`。
|
||
|
||
# 当前执行步骤 (由 EXECUTE 模式在开始执行某步骤时更新)
|
||
> 正在执行: "1. 在 `ThreatSource/src/Utils/MotionAlgorithm.cs` 中:1. 创建 `public static double CalculateAngleOfAttackFromHorizontal(Vector3D velocity)` 方法。"
|
||
|
||
# 任务进度 (由 EXECUTE 模式在每步完成后追加)
|
||
* [待填写]
|
||
|
||
# 最终审查 (由 REVIEW 模式填充)
|
||
[待填写] |