FXJHGenenrate.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. using SimulationCommon;
  2. namespace Model
  3. {
  4. public class FXJHGenerate
  5. {
  6. public static void
  7. FromStartToMission(FlightPlanEditor editor, ref List<TurningPoint> turningPoints) //生成从基地到任务段起点的航路点
  8. {
  9. turningPoints.Add(new TurningPoint
  10. {
  11. TurningPointName = "爬升",
  12. TurningPointLongitude = editor.originbase.BaseLongitude, //基地位置
  13. TurningPointLatitude = editor.originbase.BaseLatitude,
  14. TurningPointHeight = editor.originbase.BaseHeight,
  15. TurningPointType = "普通",
  16. //TurningPointVelocity = editor.climbsegment.ClimbVelocity;
  17. SegmentFlightFuelConsumption = 1,
  18. SegmentFlightTime = 0,
  19. RemainingFuel = 0,
  20. });
  21. // double k;
  22. double lat1, lon1; //直升机起飞后爬升到的航路点的经纬度,记为经纬度1
  23. lat1 = (editor.originbase.BaseLatitude + editor.missionpoint.MissionPointLatitude) / 2;
  24. lon1 = (editor.originbase.BaseLongitude + editor.missionpoint.MissionPointLongitude) / 2;
  25. // k = (editor.missionpoint.MissionPointLatitude - editor.originbase.BaseLatitude) /
  26. // (editor.missionpoint.MissionPointLongitude - editor.originbase.BaseLongitude);
  27. // if (editor.missionpoint.MissionPointLongitude > editor.originbase.BaseLongitude)
  28. // {
  29. // lat1 = 0.08544 * k / (Math.Sqrt(k * k + 1)) + editor.originbase.BaseLatitude; //经验公式
  30. // lon1 = 0.08544 / (Math.Sqrt(k * k + 1)) + editor.originbase.BaseLongitude;
  31. // }
  32. // else
  33. // {
  34. // lat1 = editor.originbase.BaseLatitude - 0.08544 * k / (Math.Sqrt(k * k + 1));
  35. // lon1 = editor.originbase.BaseLongitude - 0.08544 / (Math.Sqrt(k * k + 1));
  36. // }
  37. turningPoints.Add(new TurningPoint
  38. {
  39. TurningPointName = "平飞",
  40. TurningPointLongitude = lon1,
  41. TurningPointLatitude = lat1,
  42. TurningPointHeight = 2000,
  43. TurningPointType = "普通",
  44. SegmentFlightFuelConsumption = 2,
  45. SegmentFlightTime = 0,
  46. RemainingFuel = 0,
  47. });
  48. }
  49. //获取油耗率
  50. public static double GetClimbFuelConsumptionRate(FlightPlanEditor editor, double height, double t)
  51. {
  52. Fuel fuel = Util.GetFuel(editor.aircraftparameter.AircraftID, editor.aircraftparameter.AircraftSubType,
  53. "爬升", t.ToString(), height.ToString(),
  54. editor.aircraftparameter.MaxTakeoffWeight.ToString());
  55. if (fuel == null)
  56. {
  57. return 1100;
  58. }
  59. return fuel.oilconsume;
  60. }
  61. public static double GetCruisingFuelConsumptionRate(FlightPlanEditor editor, double height, double t)
  62. {
  63. Fuel fuel = Util.GetFuel(editor.aircraftparameter.AircraftID, editor.aircraftparameter.AircraftSubType,
  64. "平飞远航", t.ToString(), height.ToString(),
  65. editor.aircraftparameter.MaxTakeoffWeight.ToString());
  66. if (fuel == null)
  67. {
  68. return 600;
  69. }
  70. return fuel.oilconsume;
  71. }
  72. public static double GetEnduranceFuelConsumptionRate(FlightPlanEditor editor, double height, double t)
  73. {
  74. Fuel fuel = Util.GetFuel(editor.aircraftparameter.AircraftID, editor.aircraftparameter.AircraftSubType,
  75. "平飞久航", t.ToString(), height.ToString(),
  76. editor.aircraftparameter.MaxTakeoffWeight.ToString());
  77. if (fuel == null)
  78. {
  79. return 600;
  80. }
  81. return fuel.oilconsume;
  82. }
  83. public static double GetDescentFuelConsumptionRate(FlightPlanEditor editor, double height, double t)
  84. {
  85. return 2 * GetCruisingFuelConsumptionRate(editor, height, t) -
  86. GetClimbFuelConsumptionRate(editor, height, t);
  87. }
  88. public static double GetHoverFuelConsumptionRate(FlightPlanEditor editor, double height, double t = 0)
  89. {
  90. Fuel fuel = Util.GetFuel(editor.aircraftparameter.AircraftID, editor.aircraftparameter.AircraftSubType,
  91. "悬停", t.ToString(), height.ToString(),
  92. editor.aircraftparameter.MaxTakeoffWeight.ToString());
  93. if (fuel == null)
  94. {
  95. return 200;
  96. }
  97. return fuel.oilconsume;
  98. }
  99. //获取速度值
  100. public static double GetClimbVelocity(FlightPlanEditor editor, double height, double t)
  101. {
  102. Fuel fuel = Util.GetFuel(editor.aircraftparameter.AircraftID, editor.aircraftparameter.AircraftSubType,
  103. "爬升", t.ToString(), height.ToString(), editor.aircraftparameter.MaxTakeoffWeight.ToString());
  104. if (fuel == null)
  105. {
  106. return 60;
  107. }
  108. return fuel.speed;
  109. }
  110. public static double GetCruisingVelocity(FlightPlanEditor editor, double height, double t = 0)
  111. {
  112. Fuel fuel = Util.GetFuel(editor.aircraftparameter.AircraftID, editor.aircraftparameter.AircraftSubType,
  113. "平飞远航", t.ToString(), height.ToString(), editor.aircraftparameter.MaxTakeoffWeight.ToString());
  114. if (fuel == null)
  115. {
  116. return 200;
  117. }
  118. return fuel.speed;
  119. }
  120. public static double GetEnduranceVelocity(FlightPlanEditor editor, double height, double t)
  121. {
  122. Fuel fuel = Util.GetFuel(editor.aircraftparameter.AircraftID, editor.aircraftparameter.AircraftSubType,
  123. "平飞久航", t.ToString(), height.ToString(), editor.aircraftparameter.MaxTakeoffWeight.ToString());
  124. if (fuel == null)
  125. {
  126. return 200;
  127. }
  128. return fuel.speed;
  129. }
  130. public static double GetDescentVelocity(FlightPlanEditor editor, double height, double t)
  131. {
  132. return GetCruisingVelocity(editor, height, t) / 2;
  133. }
  134. public static void ZhenCha(List<double[]> SC01, FlightPlanEditor editor,
  135. ref List<TurningPoint> turningPoints) //侦查模型航路点生成
  136. {
  137. int i;
  138. for (i = 0; i < SC01.Count - 1; i++)
  139. {
  140. turningPoints.Add(new TurningPoint
  141. {
  142. TurningPointName = "平飞",
  143. TurningPointLongitude = SC01[i][0],
  144. TurningPointLatitude = SC01[i][1],
  145. TurningPointHeight = SC01[i][2],
  146. TurningPointType = "侦查",
  147. SegmentFlightFuelConsumption = 3,
  148. SegmentFlightTime = 0,
  149. RemainingFuel = 0,
  150. });
  151. }
  152. }
  153. public static void SuoHuaJiang(double resulttime, FlightPlanEditor editor,
  154. ref List<TurningPoint> turningPoints) //索滑降模型航路点生成
  155. {
  156. turningPoints.Add(new TurningPoint
  157. {
  158. TurningPointName = "索滑降",
  159. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  160. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  161. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  162. TurningPointType = "索滑降",
  163. SegmentFlightFuelConsumption = 5,
  164. SegmentFlightTime = resulttime,
  165. RemainingFuel = 0,
  166. });
  167. turningPoints.Add(new TurningPoint
  168. {
  169. TurningPointName = "索滑降",
  170. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  171. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  172. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  173. TurningPointType = "索滑降",
  174. SegmentFlightFuelConsumption = 2,
  175. SegmentFlightTime = 0,
  176. RemainingFuel = 0,
  177. });
  178. }
  179. public static void XunHu(FlightPlanEditor editor, ref List<TurningPoint> turningPoints)
  180. {
  181. int i;
  182. for (i = 0; i < editor.airroute.Length; i++)
  183. {
  184. turningPoints.Add(new TurningPoint
  185. {
  186. TurningPointName = "平飞",
  187. TurningPointLongitude = editor.airroute[i].AirRouteLongitude,
  188. TurningPointLatitude = editor.airroute[i].AirRouteLatitude,
  189. TurningPointHeight = 3000,
  190. TurningPointType = "普通",
  191. SegmentFlightFuelConsumption = 3,
  192. SegmentFlightTime = 0,
  193. RemainingFuel = 0,
  194. });
  195. }
  196. }
  197. public static void TongXin(FlightPlanEditor editor, ref List<TurningPoint> turningPoints)
  198. {
  199. int i;
  200. for (i = 0; i < editor.airroute.Length; i++)
  201. {
  202. turningPoints.Add(new TurningPoint
  203. {
  204. TurningPointName = "平飞",
  205. TurningPointLongitude = editor.airroute[i].AirRouteLongitude,
  206. TurningPointLatitude = editor.airroute[i].AirRouteLatitude,
  207. TurningPointHeight = editor.airroute[i].AirRouteHeight,
  208. TurningPointType = "普通",
  209. SegmentFlightFuelConsumption = 3,
  210. SegmentFlightTime = 0,
  211. RemainingFuel = 0,
  212. });
  213. }
  214. }
  215. public static void MieHuo1(FlightPlanEditor editor, ref List<TurningPoint> turningPoints) //灭火任务从取水点到火场部分的航路点生成
  216. {
  217. turningPoints.Add(new TurningPoint
  218. {
  219. TurningPointName = "取水",
  220. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  221. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  222. TurningPointHeight = editor.missionpoint.MissionPointHeight + 60,
  223. TurningPointType = "取水",
  224. SegmentFlightFuelConsumption = 5,
  225. SegmentFlightTime = 60,
  226. RemainingFuel = 0,
  227. });
  228. turningPoints.Add(new TurningPoint
  229. {
  230. TurningPointName = "取水",
  231. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  232. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  233. TurningPointHeight = editor.missionpoint.MissionPointHeight + 60,
  234. TurningPointType = "取水",
  235. SegmentFlightFuelConsumption = 3,
  236. SegmentFlightTime = 0,
  237. RemainingFuel = 0,
  238. });
  239. turningPoints.Add(new TurningPoint
  240. {
  241. TurningPointName = "洒水",
  242. TurningPointLongitude = editor.firepoint[0].FirePointLongitude,
  243. TurningPointLatitude = editor.firepoint[0].FirePointLatitude,
  244. TurningPointHeight = editor.firepoint[0].FirePointHeight + 60,
  245. TurningPointType = "巡航",
  246. SegmentFlightFuelConsumption = 5,
  247. SegmentFlightTime = 120,
  248. RemainingFuel = 0,
  249. });
  250. turningPoints.Add(new TurningPoint
  251. {
  252. TurningPointName = "洒水",
  253. TurningPointLongitude = editor.firepoint[0].FirePointLongitude,
  254. TurningPointLatitude = editor.firepoint[0].FirePointLatitude,
  255. TurningPointHeight = editor.firepoint[0].FirePointHeight + 60,
  256. TurningPointType = "巡航",
  257. SegmentFlightFuelConsumption = 3,
  258. SegmentFlightTime = 0,
  259. RemainingFuel = 0,
  260. });
  261. }
  262. public static MissionEndPoint ZhenChaMissionEndPoint(List<double[]> SC01) //侦查模型任务终点生成
  263. {
  264. MissionEndPoint missionEndPoint = new();
  265. int length = SC01.Count - 1;
  266. missionEndPoint.MissionEndPointLongitude = SC01[length][0];
  267. missionEndPoint.MissionEndPointLatitude = SC01[length][1];
  268. missionEndPoint.MissionEndPointHeight = SC01[length][2];
  269. return missionEndPoint;
  270. }
  271. public static MissionEndPoint SuoHuaJiangMissionEndPoint(FlightPlanEditor editor) //索滑降模型任务终点生成
  272. {
  273. MissionEndPoint missionEndPoint = new();
  274. missionEndPoint.MissionEndPointLongitude = editor.missionpoint.MissionPointLongitude;
  275. missionEndPoint.MissionEndPointLatitude = editor.missionpoint.MissionPointLatitude;
  276. missionEndPoint.MissionEndPointHeight = editor.missionpoint.MissionPointHeight;
  277. return missionEndPoint;
  278. }
  279. public static void JijiangMiehuo1(FlightPlanEditor editor, ref List<TurningPoint> turningPoint)
  280. {
  281. turningPoint.Add(new TurningPoint
  282. {
  283. TurningPointName = "转运",
  284. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  285. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  286. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  287. TurningPointType = "转运",
  288. SegmentFlightFuelConsumption = 0,
  289. SegmentFlightTime = 600,
  290. RemainingFuel = 0,
  291. });
  292. turningPoint.Add(new TurningPoint
  293. {
  294. TurningPointName = "转运",
  295. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  296. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  297. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  298. TurningPointType = "转运",
  299. SegmentFlightFuelConsumption = 2,
  300. SegmentFlightTime = 0,
  301. RemainingFuel = 0,
  302. });
  303. }
  304. public static void JijiangMiehuo(FlightPlanEditor editor, ref List<TurningPoint> turningPoint)
  305. {
  306. turningPoint.Add(new TurningPoint
  307. {
  308. TurningPointName = "转运",
  309. TurningPointLongitude = editor.originbase.BaseLongitude,
  310. TurningPointLatitude = editor.originbase.BaseLatitude,
  311. TurningPointHeight = editor.originbase.BaseHeight,
  312. TurningPointType = "转运",
  313. SegmentFlightFuelConsumption = 0,
  314. SegmentFlightTime = 600,
  315. RemainingFuel = 0,
  316. });
  317. turningPoint.Add(new TurningPoint
  318. {
  319. TurningPointName = "转运",
  320. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  321. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  322. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  323. TurningPointType = "转运",
  324. SegmentFlightFuelConsumption = 2,
  325. SegmentFlightTime = 0,
  326. RemainingFuel = 0,
  327. });
  328. turningPoint.Add(new TurningPoint
  329. {
  330. TurningPointName = "转运",
  331. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  332. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  333. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  334. TurningPointType = "转运",
  335. SegmentFlightFuelConsumption = 0,
  336. SegmentFlightTime = 600,
  337. RemainingFuel = 0,
  338. });
  339. turningPoint.Add(new TurningPoint
  340. {
  341. TurningPointName = "转运",
  342. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  343. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  344. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  345. TurningPointType = "转运",
  346. SegmentFlightFuelConsumption = 2,
  347. SegmentFlightTime = 0,
  348. RemainingFuel = 0,
  349. });
  350. }
  351. public static void KouTouKouSong(FlightPlanEditor editor, ref List<TurningPoint> turningPoint)
  352. {
  353. turningPoint.Add(new TurningPoint
  354. {
  355. TurningPointName = "转运",
  356. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  357. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  358. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  359. TurningPointType = "转运",
  360. SegmentFlightFuelConsumption = 2,
  361. SegmentFlightTime = 0,
  362. RemainingFuel = 0,
  363. });
  364. }
  365. public static void KouTouKouSong1(MissionPoint missionpoint, ref List<TurningPoint> turningPoint)
  366. {
  367. turningPoint.Add(new TurningPoint
  368. {
  369. TurningPointName = "转运",
  370. TurningPointLongitude = missionpoint.MissionPointLongitude,
  371. TurningPointLatitude = missionpoint.MissionPointLatitude,
  372. TurningPointHeight = missionpoint.MissionPointHeight,
  373. TurningPointType = "转运",
  374. SegmentFlightFuelConsumption = 2,
  375. SegmentFlightTime = 0,
  376. RemainingFuel = 0,
  377. });
  378. }
  379. public static void JijiangJiuYuan1(FlightPlanEditor editor, ref List<TurningPoint> turningPoint)
  380. {
  381. turningPoint.Add(new TurningPoint
  382. {
  383. TurningPointName = "转运",
  384. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  385. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  386. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  387. TurningPointType = "转运",
  388. SegmentFlightFuelConsumption = 2,
  389. SegmentFlightTime = 600,
  390. RemainingFuel = 0,
  391. });
  392. turningPoint.Add(new TurningPoint
  393. {
  394. TurningPointName = "转运",
  395. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  396. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  397. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  398. TurningPointType = "转运",
  399. SegmentFlightFuelConsumption = 2,
  400. SegmentFlightTime = 0,
  401. RemainingFuel = 0,
  402. });
  403. }
  404. public static void JijiangJiuYuan(FlightPlanEditor editor, ref List<TurningPoint> turningPoint)
  405. {
  406. turningPoint.Add(new TurningPoint
  407. {
  408. TurningPointName = "转运",
  409. TurningPointLongitude = editor.originbase.BaseLongitude,
  410. TurningPointLatitude = editor.originbase.BaseLatitude,
  411. TurningPointHeight = editor.originbase.BaseHeight,
  412. TurningPointType = "转运",
  413. SegmentFlightFuelConsumption = 2,
  414. SegmentFlightTime = 0,
  415. RemainingFuel = 0,
  416. });
  417. turningPoint.Add(new TurningPoint
  418. {
  419. TurningPointName = "转运",
  420. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  421. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  422. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  423. TurningPointType = "转运",
  424. SegmentFlightFuelConsumption = 2,
  425. SegmentFlightTime = 600,
  426. RemainingFuel = 0,
  427. });
  428. turningPoint.Add(new TurningPoint
  429. {
  430. TurningPointName = "转运",
  431. TurningPointLongitude = editor.missionpoint.MissionPointLongitude,
  432. TurningPointLatitude = editor.missionpoint.MissionPointLatitude,
  433. TurningPointHeight = editor.missionpoint.MissionPointHeight,
  434. TurningPointType = "转运",
  435. SegmentFlightFuelConsumption = 2,
  436. SegmentFlightTime = 0,
  437. RemainingFuel = 0,
  438. });
  439. }
  440. public static void ZhaoShuiJiuYuan(List<AirRoute> airRoutes, ref List<TurningPoint> turningPoint)
  441. {
  442. for (int i = 0; i < airRoutes.Count; i++)
  443. {
  444. turningPoint.Add(new TurningPoint
  445. {
  446. TurningPointName = "转运",
  447. TurningPointLongitude = airRoutes[i].AirRouteLongitude,
  448. TurningPointLatitude = airRoutes[i].AirRouteLatitude,
  449. TurningPointHeight = 1000,
  450. TurningPointType = "转运",
  451. SegmentFlightFuelConsumption = 3,
  452. SegmentFlightTime = 0,
  453. RemainingFuel = 0,
  454. });
  455. }
  456. }
  457. public static void ZhaoShuiJiuYuan1(List<AirRoute> airRoutes, ref List<TurningPoint> turningPoint)
  458. {
  459. turningPoint.Add(new TurningPoint
  460. {
  461. TurningPointName = "转运",
  462. TurningPointLongitude = airRoutes[airRoutes.Count - 1].AirRouteLongitude,
  463. TurningPointLatitude = airRoutes[airRoutes.Count - 1].AirRouteLatitude,
  464. TurningPointHeight = 1000,
  465. TurningPointType = "转运",
  466. SegmentFlightFuelConsumption = 3,
  467. SegmentFlightTime = 1800,
  468. RemainingFuel = 0,
  469. });
  470. }
  471. public static void SeaSouJiu(FlightPlanEditor editor, ref List<TurningPoint> turningPoints)
  472. {
  473. int i;
  474. for (i = 0; i < editor.airroute.Length; i++)
  475. {
  476. turningPoints.Add(new TurningPoint
  477. {
  478. TurningPointName = "巡航",
  479. TurningPointLongitude = editor.airroute[i].AirRouteLongitude,
  480. TurningPointLatitude = editor.airroute[i].AirRouteLatitude,
  481. TurningPointHeight = 150,
  482. TurningPointType = "普通",
  483. SegmentFlightFuelConsumption = 3,
  484. SegmentFlightTime = 0,
  485. RemainingFuel = 0,
  486. });
  487. }
  488. }
  489. public static void SeaSouJiu2(FlightPlanEditor editor, MissionPoint missionPoint,
  490. ref List<TurningPoint> turningPoints)
  491. {
  492. turningPoints.Add(new TurningPoint
  493. {
  494. TurningPointName = "巡航",
  495. TurningPointLongitude = missionPoint.MissionPointLongitude,
  496. TurningPointLatitude = missionPoint.MissionPointLatitude,
  497. TurningPointHeight = 0,
  498. TurningPointType = "普通",
  499. SegmentFlightFuelConsumption = 3,
  500. SegmentFlightTime = 0,
  501. RemainingFuel = 0,
  502. });
  503. }
  504. public static double CalculateTotalFuelConsumption(FlightPlanEditor editor, List<TurningPoint> turningPoints)
  505. {
  506. double initialFuel = editor.aircraftparameter.MaxFuelCapacity; // 起始燃油量
  507. double totalFuelConsumption = 0; // 总燃油消耗量
  508. double totalRefuelAmount = 0; // 总加油量
  509. for (int i = 0; i < turningPoints.Count; i++)
  510. {
  511. //// 更新飞行过程中的燃油消耗
  512. //if (i ==0)
  513. //{
  514. // double segmentFuelConsumed = initialFuel - turningPoints[i].RemainingFuel;
  515. //}
  516. //else
  517. //{
  518. // double segmentFuelConsumed = (turningPoints[i - 1].RemainingFuel - turningPoints[i].RemainingFuel);
  519. // totalFuelConsumption += segmentFuelConsumed;
  520. //}
  521. // 如果当前航路点是加油点,更新燃油并记录加油量
  522. if (turningPoints[i].TurningPointType == "加油")
  523. {
  524. double refuelAmount = editor.aircraftparameter.MaxFuelCapacity - turningPoints[i - 2].RemainingFuel;
  525. totalRefuelAmount += refuelAmount;
  526. }
  527. }
  528. // 最终燃油消耗 = 初始燃油 + 总加油量 - 最终剩余燃油
  529. double finalFuel = turningPoints.Last().RemainingFuel;
  530. totalFuelConsumption = (initialFuel + totalRefuelAmount) - finalFuel;
  531. return totalFuelConsumption;
  532. }
  533. public static void LandSouJiu(FlightPlanEditor editor, ref List<TurningPoint> turningPoints)
  534. {
  535. int i;
  536. for (i = 0; i < editor.airroute.Length; i++)
  537. {
  538. turningPoints.Add(new TurningPoint
  539. {
  540. TurningPointName = "巡航",
  541. TurningPointLongitude = editor.airroute[i].AirRouteLongitude,
  542. TurningPointLatitude = editor.airroute[i].AirRouteLatitude,
  543. TurningPointHeight = editor.airroute[i].AirRouteHeight,
  544. TurningPointType = "普通",
  545. SegmentFlightFuelConsumption = 3,
  546. SegmentFlightTime = 0,
  547. RemainingFuel = 0,
  548. });
  549. }
  550. }
  551. public static void FromMissionToEnd(FlightPlanEditor editor, MissionEndPoint missionEndPoint,
  552. ref List<TurningPoint> turningPoints) //生成从任务段终点到基地的航路点
  553. {
  554. turningPoints.Add(new TurningPoint
  555. {
  556. TurningPointName = "平飞",
  557. TurningPointLongitude = missionEndPoint.MissionEndPointLongitude,
  558. TurningPointLatitude = missionEndPoint.MissionEndPointLatitude,
  559. TurningPointHeight = missionEndPoint.MissionEndPointHeight,
  560. TurningPointType = "普通",
  561. SegmentFlightFuelConsumption = 3,
  562. SegmentFlightTime = 0,
  563. RemainingFuel = 0,
  564. });
  565. //double k;
  566. double lat2, lon2;
  567. lat2 = (turningPoints[^1].TurningPointLatitude + editor.endbase.BaseLatitude) / 2;
  568. lon2 = (turningPoints[^1].TurningPointLongitude + editor.endbase.BaseLongitude) / 2;
  569. // k = (turningPoints[^1].TurningPointLatitude - editor.originbase.BaseLatitude) /
  570. // (turningPoints[^1].TurningPointLongitude - editor.originbase.BaseLongitude);
  571. // if (turningPoints[^1].TurningPointLongitude > editor.originbase.BaseLongitude)
  572. // {
  573. // lat2 = 0.08544 * k / (Math.Sqrt(k * k + 1)) + editor.originbase.BaseLatitude;
  574. // lon2 = 0.08544 / (Math.Sqrt(k * k + 1)) + editor.originbase.BaseLongitude;
  575. // }
  576. // else
  577. // {
  578. // lat2 = editor.originbase.BaseLatitude - 0.08544 * k / (Math.Sqrt(k * k + 1));
  579. // lon2 = editor.originbase.BaseLongitude - 0.08544 / (Math.Sqrt(k * k + 1));
  580. // }
  581. turningPoints.Add(new TurningPoint
  582. {
  583. TurningPointName = "降高",
  584. TurningPointLongitude = lon2,
  585. TurningPointLatitude = lat2,
  586. TurningPointHeight = 2000,
  587. TurningPointType = "普通",
  588. SegmentFlightFuelConsumption = 4,
  589. SegmentFlightTime = 0,
  590. RemainingFuel = 0,
  591. });
  592. turningPoints.Add(new TurningPoint
  593. {
  594. TurningPointName = "返回基地",
  595. TurningPointLongitude = editor.endbase.BaseLongitude,
  596. TurningPointLatitude = editor.endbase.BaseLatitude,
  597. TurningPointHeight = editor.endbase.BaseHeight,
  598. TurningPointType = "普通",
  599. SegmentFlightFuelConsumption = 4,
  600. SegmentFlightTime = 0,
  601. RemainingFuel = 0,
  602. });
  603. }
  604. public static void InitializeVelocities(FlightPlanEditor editor, List<TurningPoint> turningPoints,
  605. ref double[] velocitys, double t)
  606. {
  607. velocitys[0] = GetClimbVelocity(editor, turningPoints[0].TurningPointHeight, t);
  608. velocitys[1] = GetCruisingVelocity(editor, turningPoints[1].TurningPointHeight, t);
  609. velocitys[2] = GetEnduranceVelocity(editor, turningPoints[2].TurningPointHeight, t);
  610. velocitys[3] = GetDescentVelocity(editor, turningPoints[0].TurningPointHeight, t);
  611. }
  612. public static void InitializeFuelConsumptions(FlightPlanEditor editor, List<TurningPoint> turningPoints,
  613. ref double[] fuelConsumptions, double t)
  614. {
  615. fuelConsumptions[0] = GetClimbFuelConsumptionRate(editor, turningPoints[0].TurningPointHeight, t);
  616. fuelConsumptions[1] = GetCruisingFuelConsumptionRate(editor, turningPoints[1].TurningPointHeight, t);
  617. fuelConsumptions[2] = GetEnduranceFuelConsumptionRate(editor, turningPoints[2].TurningPointHeight, t);
  618. fuelConsumptions[3] = GetDescentFuelConsumptionRate(editor, turningPoints[0].TurningPointHeight, t);
  619. fuelConsumptions[4] = GetHoverFuelConsumptionRate(editor, turningPoints[2].TurningPointHeight, t);
  620. }
  621. public static void CalculateTrueHeading(FlightPlanEditor editor, ref List<TurningPoint> turningPoints)
  622. {
  623. for (int i = 0; i < turningPoints.Count - 1; i++)
  624. {
  625. // 转换为弧度
  626. double lat1Rad = turningPoints[i].TurningPointLatitude * Math.PI / 180;
  627. double lon1Rad = turningPoints[i].TurningPointLongitude * Math.PI / 180;
  628. double lat2Rad = turningPoints[i + 1].TurningPointLatitude * Math.PI / 180;
  629. double lon2Rad = turningPoints[i + 1].TurningPointLongitude * Math.PI / 180;
  630. double deltaLon = lon2Rad - lon1Rad;
  631. double x = Math.Sin(deltaLon) * Math.Cos(lat2Rad);
  632. double y = Math.Cos(lat1Rad) * Math.Sin(lat2Rad) -
  633. Math.Sin(lat1Rad) * Math.Cos(lat2Rad) * Math.Cos(deltaLon);
  634. // 计算航向角
  635. double headingRad = Math.Atan2(x, y);
  636. // 转换为度并标准化
  637. double headingDeg = headingRad * 180 / Math.PI;
  638. headingDeg = (headingDeg + 360) % 360;
  639. turningPoints[i].HeadingAngle = headingDeg;
  640. }
  641. }
  642. public static void FXJHTPDiedai(FlightPlanEditor editor, ref List<TurningPoint> turningPoints,
  643. double[] velocitys, double[] fuelConsumptions)
  644. {
  645. int i;
  646. double DEG_TO_RAD_LOCAL = 3.1415926535897932 / 180;
  647. double[] x = new double[turningPoints.Count];
  648. double[] y = new double[turningPoints.Count];
  649. double[] z = new double[turningPoints.Count];
  650. // LLA坐标转换为ECEF坐标
  651. for (i = 0; i < turningPoints.Count; i++)
  652. {
  653. double lon = turningPoints[i].TurningPointLongitude * DEG_TO_RAD_LOCAL;
  654. double lat = turningPoints[i].TurningPointLatitude * DEG_TO_RAD_LOCAL;
  655. double hei = turningPoints[i].TurningPointHeight;
  656. double a = 6378137.0;
  657. double b = 6356752.31424518;
  658. double N = a / (Math.Sqrt(1 - ((a * a - b * b) / (a * a)) * Math.Sin(lat) * Math.Sin(lat)));
  659. x[i] = (N + hei) * Math.Cos(lat) * Math.Cos(lon);
  660. y[i] = (N + hei) * Math.Cos(lat) * Math.Sin(lon);
  661. z[i] = ((b * b * N) / (a * a) + hei) * Math.Sin(lat);
  662. }
  663. // 计算每个航段的飞行时间
  664. for (i = 0; i < turningPoints.Count; i++)
  665. {
  666. if (turningPoints[i].SegmentFlightTime == 0)
  667. {
  668. double distanceab = 0;
  669. if (i != turningPoints.Count - 1)
  670. {
  671. distanceab = Math.Sqrt(Math.Pow(x[i] - x[i + 1], 2) + Math.Pow(y[i] - y[i + 1], 2) +
  672. Math.Pow(z[i] - z[i + 1], 2));
  673. }
  674. double velocity;
  675. switch (turningPoints[i].SegmentFlightFuelConsumption)
  676. {
  677. case 1:
  678. velocity = velocitys[0];
  679. break;
  680. case 2:
  681. velocity = velocitys[1];
  682. break;
  683. case 3:
  684. velocity = velocitys[2];
  685. break;
  686. case 4:
  687. velocity = velocitys[3];
  688. break;
  689. case 5:
  690. velocity = 0;
  691. break;
  692. default:
  693. velocity = 0;
  694. break;
  695. }
  696. turningPoints[i].SegmentFlightTime = CalculateSegmentFlightTime(distanceab, velocity);
  697. double CalculateSegmentFlightTime(double distance, double velocit)
  698. {
  699. return distance * 3.6 / velocit;
  700. }
  701. // 打印调试信息
  702. //Console.WriteLine($"航段 {i}: 时间 = {turningPoints[i].SegmentFlightTime} s, 速度 = {velocity} km/h, 距离 = {distanceab} m");
  703. }
  704. //Console.WriteLine($"航段 {i}: 时间 = {turningPoints[i].SegmentFlightTime} s");
  705. // 计算燃油消耗,并在燃油不足时插入“返回基地”、“加油”和“返回原航路点”航路点
  706. if (turningPoints[i].RemainingFuel == 0)
  707. {
  708. double remainingFuel;
  709. if (i == 0)
  710. {
  711. remainingFuel = editor.aircraftparameter.MaxFuelCapacity * 0.8;
  712. }
  713. else
  714. {
  715. remainingFuel = turningPoints[i - 1].RemainingFuel;
  716. }
  717. double fuelConsumption = 0;
  718. switch (turningPoints[i].SegmentFlightFuelConsumption)
  719. {
  720. case 1:
  721. fuelConsumption = fuelConsumptions[0];
  722. break;
  723. case 2:
  724. fuelConsumption = fuelConsumptions[1];
  725. break;
  726. case 3:
  727. fuelConsumption = fuelConsumptions[2];
  728. break;
  729. case 4:
  730. fuelConsumption = fuelConsumptions[3];
  731. break;
  732. case 5:
  733. fuelConsumption = fuelConsumptions[4];
  734. break;
  735. default:
  736. fuelConsumption = 0;
  737. break;
  738. }
  739. remainingFuel -= fuelConsumption * turningPoints[i].SegmentFlightTime / 3600;
  740. turningPoints[i].RemainingFuel = remainingFuel;
  741. // 打印调试信息
  742. //Console.WriteLine($"航段 {i}: 油耗率 = {fuelConsumption} kg/h, 剩余燃油 = {turningPoints[i].RemainingFuel} kg");
  743. }
  744. //Console.WriteLine($"航段 {i}: 剩余燃油 = {turningPoints[i].RemainingFuel} kg");
  745. if (turningPoints[i].RemainingFuel < editor.aircraftparameter.MaxFuelCapacity * 0.2 &&
  746. !turningPoints[i].IsRefuelPointInserted && i < turningPoints.Count - 2)
  747. {
  748. // 标记当前航路点为已插入加油点
  749. turningPoints[i].IsRefuelPointInserted = true;
  750. turningPoints[i + 1].IsRefuelPointInserted = true;
  751. TurningPoint returnToBase = new TurningPoint
  752. {
  753. TurningPointName = "返回基地",
  754. TurningPointLongitude = editor.fuelbase.BaseLongitude,
  755. TurningPointLatitude = editor.fuelbase.BaseLatitude,
  756. TurningPointHeight = editor.fuelbase.BaseHeight,
  757. TurningPointType = "返航",
  758. SegmentFlightTime = 600,
  759. SegmentFlightFuelConsumption = 0,
  760. RemainingFuel = editor.aircraftparameter.MaxFuelCapacity,
  761. };
  762. TurningPoint refuelPoint = new TurningPoint
  763. {
  764. TurningPointName = "加油",
  765. TurningPointLongitude = editor.fuelbase.BaseLongitude,
  766. TurningPointLatitude = editor.fuelbase.BaseLatitude,
  767. TurningPointHeight = editor.fuelbase.BaseHeight,
  768. TurningPointType = "加油",
  769. SegmentFlightTime = 0,
  770. SegmentFlightFuelConsumption = 2,
  771. RemainingFuel = 0,
  772. };
  773. TurningPoint returnToPrevious = new TurningPoint
  774. {
  775. TurningPointName = "返回原航路点",
  776. TurningPointLongitude = turningPoints[i + 1].TurningPointLongitude,
  777. TurningPointLatitude = turningPoints[i + 1].TurningPointLatitude,
  778. TurningPointHeight = turningPoints[i + 1].TurningPointHeight,
  779. TurningPointType = "返航",
  780. SegmentFlightTime = 0,
  781. SegmentFlightFuelConsumption = 2,
  782. RemainingFuel = 0,
  783. };
  784. // 插入新航路点到当前位置
  785. turningPoints.Insert(i + 2, returnToBase);
  786. turningPoints.Insert(i + 3, refuelPoint);
  787. turningPoints.Insert(i + 4, returnToPrevious);
  788. // 重新计算插入的航路点的飞行时间和燃油消耗
  789. FXJHTPDiedai(editor, ref turningPoints, velocitys, fuelConsumptions);
  790. // 退出当前方法,避免重复计算
  791. return;
  792. }
  793. }
  794. }
  795. /// <summary>
  796. /// 巡护用
  797. /// </summary>
  798. /// <param name="turningPoints"></param>
  799. /// <param name="editor"></param>
  800. /// <param name="nowtime"></param>
  801. /// <returns></returns>
  802. public static (CurrentLocation, bool) GetCurrentLocation(List<TurningPoint> turningPoints,
  803. FlightPlanEditor editor,
  804. double nowtime)
  805. {
  806. CurrentLocation currentLocation = new CurrentLocation();
  807. double[] timetable = new double[editor.airroute.Length + 2]; //airroute.Length表示巡护航线中有几个航路点
  808. timetable[0] = 0; //设起飞时刻为0
  809. int segmentnumber = -1;
  810. int i;
  811. for (i = 0; i < editor.airroute.Length + 1; i++)
  812. {
  813. timetable[i + 1] = timetable[i] + turningPoints[i].SegmentFlightTime;
  814. }
  815. for (i = 0; i < editor.airroute.Length + 2; i++)
  816. {
  817. if ((nowtime - timetable[i]) >= 0)
  818. {
  819. segmentnumber += 1;
  820. }
  821. else
  822. {
  823. break;
  824. }
  825. }
  826. bool isEnd = false || segmentnumber >= turningPoints.Count;
  827. currentLocation.CurrentLon = turningPoints[segmentnumber].TurningPointLongitude +
  828. (turningPoints[segmentnumber + 1].TurningPointLongitude -
  829. turningPoints[segmentnumber].TurningPointLongitude) *
  830. (nowtime - timetable[segmentnumber]) /
  831. turningPoints[segmentnumber].SegmentFlightTime;
  832. currentLocation.CurrentLat = turningPoints[segmentnumber].TurningPointLatitude +
  833. (turningPoints[segmentnumber + 1].TurningPointLatitude -
  834. turningPoints[segmentnumber].TurningPointLatitude) *
  835. (nowtime - timetable[segmentnumber]) /
  836. turningPoints[segmentnumber].SegmentFlightTime;
  837. currentLocation.CurrentHei = turningPoints[segmentnumber].TurningPointHeight +
  838. (turningPoints[segmentnumber + 1].TurningPointHeight -
  839. turningPoints[segmentnumber].TurningPointHeight) *
  840. (nowtime - timetable[segmentnumber]) /
  841. turningPoints[segmentnumber].SegmentFlightTime;
  842. currentLocation.CurrentFuel = 0;
  843. currentLocation.Currentvelo = 0;
  844. currentLocation.Currentsegnum = segmentnumber + 1;
  845. currentLocation.CurrentCourse = 75;
  846. return (currentLocation, isEnd);
  847. }
  848. //改
  849. /// <summary>
  850. /// 计算当前位置
  851. /// </summary>
  852. /// <param name="FXJHTP"></param>
  853. /// <param name="FXJHTPLength"></param>
  854. /// <param name="nowtime"></param>
  855. /// <returns></returns>
  856. // public static (CurrentLocation, bool, int)
  857. // GetAllCurrentLocation(List<TurningPoint> turningPoints, double nowtime) //飞机实时位置打印
  858. // {
  859. // CurrentLocation currentLocation = new CurrentLocation();
  860. // double[] timetable = new double[turningPoints.Count + 1];
  861. // timetable[0] = 0;
  862. // int segmentnumber = -1;
  863. // int i;
  864. // for (i = 0; i < turningPoints.Count; i++)
  865. // {
  866. // timetable[i + 1] = timetable[i] + turningPoints[i].SegmentFlightTime;
  867. // }
  868. //
  869. // for (i = 0; i < turningPoints.Count + 1; i++)
  870. // {
  871. // if ((nowtime - timetable[i]) >= 0)
  872. // {
  873. // segmentnumber += 1;
  874. // }
  875. // else
  876. // {
  877. // break;
  878. // }
  879. // }
  880. //
  881. // bool isEnd = false || segmentnumber >= turningPoints.Count;
  882. //
  883. // currentLocation.Currentsegnum = segmentnumber;
  884. // if (segmentnumber < turningPoints.Count - 1)
  885. // {
  886. // currentLocation.CurrentLon = turningPoints[segmentnumber].TurningPointLongitude +
  887. // ((turningPoints[segmentnumber + 1].TurningPointLongitude -
  888. // turningPoints[segmentnumber].TurningPointLongitude) /
  889. // turningPoints[segmentnumber].SegmentFlightTime) *
  890. // (nowtime - timetable[segmentnumber]);
  891. // currentLocation.CurrentLat = turningPoints[segmentnumber].TurningPointLatitude +
  892. // ((turningPoints[segmentnumber + 1].TurningPointLatitude -
  893. // turningPoints[segmentnumber].TurningPointLatitude) /
  894. // turningPoints[segmentnumber].SegmentFlightTime) *
  895. // (nowtime - timetable[segmentnumber]);
  896. // currentLocation.CurrentHei = turningPoints[segmentnumber].TurningPointHeight +
  897. // ((turningPoints[segmentnumber + 1].TurningPointHeight -
  898. // turningPoints[segmentnumber].TurningPointHeight) /
  899. // turningPoints[segmentnumber].SegmentFlightTime) *
  900. // (nowtime - timetable[segmentnumber]);
  901. // currentLocation.CurrentFuel = turningPoints[segmentnumber].RemainingFuel -
  902. // turningPoints[segmentnumber].SegmentFlightFuelConsumption *
  903. // (nowtime - timetable[segmentnumber]);
  904. // currentLocation.PresentMission = turningPoints[segmentnumber].TurningPointName;
  905. // }
  906. // else if (segmentnumber == turningPoints.Count - 1)
  907. // {
  908. // currentLocation.CurrentLon = turningPoints[segmentnumber].TurningPointLongitude +
  909. // ((turningPoints[0].TurningPointLongitude -
  910. // turningPoints[segmentnumber].TurningPointLongitude) /
  911. // turningPoints[segmentnumber].SegmentFlightTime) *
  912. // (nowtime - timetable[segmentnumber]);
  913. // currentLocation.CurrentLat = turningPoints[segmentnumber].TurningPointLatitude +
  914. // ((turningPoints[0].TurningPointLatitude -
  915. // turningPoints[segmentnumber].TurningPointLatitude) /
  916. // turningPoints[segmentnumber].SegmentFlightTime) *
  917. // (nowtime - timetable[segmentnumber]);
  918. // currentLocation.CurrentHei = turningPoints[segmentnumber].TurningPointHeight +
  919. // ((turningPoints[0].TurningPointHeight -
  920. // turningPoints[segmentnumber].TurningPointHeight) /
  921. // turningPoints[segmentnumber].SegmentFlightTime) *
  922. // (nowtime - timetable[segmentnumber]);
  923. // currentLocation.CurrentFuel = turningPoints[segmentnumber].RemainingFuel -
  924. // turningPoints[segmentnumber].SegmentFlightFuelConsumption *
  925. // (nowtime - timetable[segmentnumber]);
  926. // currentLocation.PresentMission = turningPoints[segmentnumber].TurningPointName;
  927. // }
  928. // else
  929. // {
  930. // currentLocation.CurrentLon = turningPoints[^1].TurningPointLongitude;
  931. // currentLocation.CurrentLat = turningPoints[^1].TurningPointLatitude;
  932. // currentLocation.CurrentHei = turningPoints[^1].TurningPointHeight;
  933. // currentLocation.Currentvelo = 0;
  934. // currentLocation.CurrentFuel = turningPoints[segmentnumber - 1].RemainingFuel -
  935. // turningPoints[segmentnumber - 1].SegmentFlightFuelConsumption *
  936. // turningPoints[segmentnumber - 1].SegmentFlightTime;
  937. // currentLocation.PresentMission = turningPoints[segmentnumber - 1].TurningPointName;
  938. //
  939. // isEnd = true;
  940. // }
  941. //
  942. // return (currentLocation, isEnd, segmentnumber);
  943. // }
  944. public static List<List<Point3D>> StoreFlightPaths(ref List<TurningPoint> turningPoints,
  945. List<Point3D> areaPoints)
  946. {
  947. List<List<Point3D>> allPaths = new List<List<Point3D>>();
  948. for (int i = 0; i < turningPoints.Count - 1; i++)
  949. {
  950. var start = turningPoints[i];
  951. var end = turningPoints[i + 1];
  952. List<Point3D> path;
  953. if (start.TurningPointLongitude == end.TurningPointLongitude &&
  954. start.TurningPointLatitude == end.TurningPointLatitude)
  955. {
  956. // 经纬度相同,直接存储起点和终点
  957. path = new List<Point3D>
  958. {
  959. new Point3D
  960. {
  961. Lon = start.TurningPointLongitude, Lat = start.TurningPointLatitude,
  962. Z = start.TurningPointHeight
  963. },
  964. new Point3D
  965. {
  966. Lon = end.TurningPointLongitude, Lat = end.TurningPointLatitude, Z = end.TurningPointHeight
  967. }
  968. };
  969. }
  970. else
  971. {
  972. var start3D = new Point3D
  973. {
  974. Lon = start.TurningPointLongitude, Lat = start.TurningPointLatitude,
  975. Z = start.TurningPointHeight
  976. };
  977. var end3D = new Point3D
  978. { Lon = end.TurningPointLongitude, Lat = end.TurningPointLatitude, Z = end.TurningPointHeight };
  979. // 调用路径规划方法
  980. path = FlightPlanner.PlanFlightPath(start3D, end3D, areaPoints);
  981. // 创建新的路径列表
  982. // List<Point3D> adjustedPath = new List<Point3D>();
  983. //
  984. // // 添加第一个点
  985. // adjustedPath.Add(new Point3D
  986. // {
  987. // Lon = path[0].Lon,
  988. // Lat = path[0].Lat,
  989. // Z = path[0].Z
  990. // });
  991. //
  992. // // 遍历路径中间点
  993. // for (int j = 1; j < path.Count - 1; j++)
  994. // {
  995. // adjustedPath.Add(new Point3D
  996. // {
  997. // Lon = path[j].Lon,
  998. // Lat = path[j].Lat,
  999. // Z = path[j].Z + 300 // 加300
  1000. // });
  1001. // }
  1002. //
  1003. // // 添加最后一个点
  1004. // adjustedPath.Add(new Point3D
  1005. // {
  1006. // Lon = path[path.Count - 1].Lon,
  1007. // Lat = path[path.Count - 1].Lat,
  1008. // Z = path[path.Count - 1].Z
  1009. // });
  1010. allPaths.Add(path);
  1011. }
  1012. }
  1013. return allPaths;
  1014. }
  1015. public static CurrentLocation GetCurrentLocationNew(List<TurningPoint> turningPoints,
  1016. List<List<Point3D>> allPaths, double currentTime)
  1017. {
  1018. double accumulatedTime = 0; // 累积飞行时间
  1019. CurrentLocation currentLocation = new CurrentLocation();
  1020. for (int i = 0; i < turningPoints.Count - 1; i++)
  1021. {
  1022. TurningPoint startPoint = turningPoints[i];
  1023. double segmentTime = startPoint.SegmentFlightTime;
  1024. if (currentTime >= accumulatedTime && currentTime <= accumulatedTime + segmentTime)
  1025. {
  1026. // 当前时间在这个航路段中,找到对应路径
  1027. List<Point3D> pathSegment = allPaths[i];
  1028. // 计算该航段的飞行进度
  1029. double timeInSegment = currentTime - accumulatedTime;
  1030. double progress = timeInSegment / segmentTime; // 当前航段内的总进度比例
  1031. // 根据进度计算当前路径段的位置
  1032. double totalDistance = 0;
  1033. List<double> distances = new List<double>();
  1034. // 计算路径段的总距离及每两个点之间的距离
  1035. for (int j = 0; j < pathSegment.Count - 1; j++)
  1036. {
  1037. double distance = CalculateDistance(pathSegment[j], pathSegment[j + 1]);
  1038. distances.Add(distance);
  1039. totalDistance += distance;
  1040. }
  1041. // 找到当前进度在总路径中的距离
  1042. double targetDistance = totalDistance * progress;
  1043. double accumulatedDistance = 0;
  1044. // 遍历路径段,找到当前进度对应的两个点之间
  1045. for (int j = 0; j < pathSegment.Count - 1; j++)
  1046. {
  1047. accumulatedDistance += distances[j];
  1048. if (accumulatedDistance >= targetDistance)
  1049. {
  1050. // 线性插值计算当前位置
  1051. double segmentProgress =
  1052. (targetDistance - (accumulatedDistance - distances[j])) / distances[j];
  1053. Point3D currentPointStart = pathSegment[j];
  1054. Point3D currentPointEnd = pathSegment[j + 1];
  1055. currentLocation.CurrentLon = currentPointStart.Lon +
  1056. (currentPointEnd.Lon - currentPointStart.Lon) *
  1057. segmentProgress;
  1058. currentLocation.CurrentLat = currentPointStart.Lat +
  1059. (currentPointEnd.Lat - currentPointStart.Lat) *
  1060. segmentProgress;
  1061. currentLocation.CurrentHei = currentPointStart.Z +
  1062. (currentPointEnd.Z - currentPointStart.Z) * segmentProgress;
  1063. // 设置当前航段数,从0开始计数
  1064. currentLocation.Currentsegnum = i; // 使用TurningPoint列表的索引
  1065. return currentLocation;
  1066. }
  1067. }
  1068. }
  1069. accumulatedTime += segmentTime;
  1070. }
  1071. // 如果超过总飞行时间,返回最后一个点的位置
  1072. List<Point3D> lastPath = allPaths.Last();
  1073. Point3D lastPoint = lastPath.Last();
  1074. currentLocation.CurrentLon = lastPoint.Lon;
  1075. currentLocation.CurrentLat = lastPoint.Lat;
  1076. currentLocation.CurrentHei = lastPoint.Z;
  1077. // 设置当前航段数为最后一个TurningPoint的索引
  1078. currentLocation.Currentsegnum = turningPoints.Count - 1;
  1079. currentLocation.EndLocation = true;
  1080. return currentLocation;
  1081. }
  1082. // 计算两个点之间的距离
  1083. private static double CalculateDistance(Point3D p1, Point3D p2)
  1084. {
  1085. return Math.Sqrt(Math.Pow(p2.Lon - p1.Lon, 2) + Math.Pow(p2.Lat - p1.Lat, 2) + Math.Pow(p2.Z - p1.Z, 2));
  1086. }
  1087. }
  1088. }