LeoErrorEllipseHelper.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using XdCxRhDW.Dto;
  8. namespace XdCxRhDW.Api
  9. {
  10. public class ErrorEllipseX1Option
  11. {
  12. /// <summary>
  13. /// 第一时刻星历
  14. /// </summary>
  15. public double[] MsEph { get; set; }
  16. /// <summary>
  17. ///第二时刻星历
  18. /// </summary>
  19. public double[] NsEph1 { get; set; }
  20. /// <summary>
  21. /// 第三时刻星历
  22. /// </summary>
  23. public double[] NsEph2 { get; set; }
  24. /// <summary>
  25. /// 定位点
  26. /// </summary>
  27. public double[] SelectPoint { get; set; }
  28. /// <summary>
  29. /// 频差误差(Hz)
  30. /// </summary>
  31. public double DfoErr { get; set; }
  32. /// <summary>
  33. /// 星历位置误差
  34. /// </summary>
  35. public double EphPosErr { get; set; }
  36. /// <summary>
  37. ///星历速度误差
  38. /// </summary>
  39. public double EphVelErr { get; set; }
  40. /// <summary>
  41. /// 上行频点(Hz)
  42. /// </summary>
  43. public double fu { get; set; }
  44. /// <summary>
  45. /// 概率 默认0.5
  46. /// </summary>
  47. public double Pe { get; set; } = 0.5;
  48. }
  49. public class ErrorEllipseX2Option
  50. {
  51. /// <summary>
  52. /// 主星星历
  53. /// </summary>
  54. public double[] MsEph { get; set; }
  55. /// <summary>
  56. /// 邻星星历
  57. /// </summary>
  58. public double[] NsEph { get; set; }
  59. /// <summary>
  60. /// 参考站位置
  61. /// </summary>
  62. public double[] RefGeod { get; set; }
  63. /// <summary>
  64. /// 定位点
  65. /// </summary>
  66. public double[] SelectPoint { get; set; }
  67. /// <summary>
  68. /// 时差误差(s)
  69. /// </summary>
  70. public double DtoErr { get; set; }
  71. /// <summary>
  72. /// 频差误差(Hz)
  73. /// </summary>
  74. public double DfoErr { get; set; }
  75. /// <summary>
  76. /// 星历位置误差
  77. /// </summary>
  78. public double EphPosErr { get; set; }
  79. /// <summary>
  80. ///星历速度误差
  81. /// </summary>
  82. public double EphVelErr { get; set; }
  83. /// <summary>
  84. /// 上行频点1(Hz)
  85. /// </summary>
  86. public double fu1 { get; set; }
  87. /// <summary>
  88. /// 上行频点2(Hz)
  89. /// </summary>
  90. public double fu2 { get; set; }
  91. /// <summary>
  92. /// 概率 默认0.5
  93. /// </summary>
  94. public double Pe { get; set; } = 0.5;
  95. }
  96. public class ErrorEllipseX3Option
  97. {
  98. /// <summary>
  99. /// 主星星历
  100. /// </summary>
  101. public double[] MsEph { get; set; }
  102. /// <summary>
  103. /// 邻星星历
  104. /// </summary>
  105. public double[] NsEph1 { get; set; }
  106. /// <summary>
  107. /// 邻星星历
  108. /// </summary>
  109. public double[] NsEph2 { get; set; }
  110. /// <summary>
  111. /// 参考站位置
  112. /// </summary>
  113. public double[] RefGeod { get; set; }
  114. /// <summary>
  115. /// 定位点
  116. /// </summary>
  117. public double[] SelectPoint { get; set; }
  118. /// <summary>
  119. /// 时差误差(s)
  120. /// </summary>
  121. public double DtoErr { get; set; }
  122. /// <summary>
  123. /// 频差误差(Hz)
  124. /// </summary>
  125. public double DfoErr { get; set; }
  126. /// <summary>
  127. /// 星历位置误差
  128. /// </summary>
  129. public double EphPosErr { get; set; }
  130. /// <summary>
  131. ///星历速度误差
  132. /// </summary>
  133. public double EphVelErr { get; set; }
  134. /// <summary>
  135. /// 上行频点1(Hz)
  136. /// </summary>
  137. public double fu1 { get; set; }
  138. /// <summary>
  139. /// 上行频点2(Hz)
  140. /// </summary>
  141. public double fu2 { get; set; }
  142. /// <summary>
  143. /// 概率 默认0.5
  144. /// </summary>
  145. public double Pe { get; set; } = 0.5;
  146. }
  147. public class ErrorEllipse2X1DOption
  148. {
  149. /// <summary>
  150. /// 主星星历
  151. /// </summary>
  152. public double[] MsEph { get; set; }
  153. /// <summary>
  154. /// 邻星星历
  155. /// </summary>
  156. public double[] NsEph { get; set; }
  157. /// <summary>
  158. /// 超短波位置
  159. /// </summary>
  160. public double[] CDBAnt { get; set; }
  161. /// <summary>
  162. /// 参考站位置
  163. /// </summary>
  164. public double[] RefGeod { get; set; }
  165. /// <summary>
  166. /// 定位点
  167. /// </summary>
  168. public double[] SelectPoint { get; set; }
  169. /// <summary>
  170. /// 时差误差(s)
  171. /// </summary>
  172. public double DtoErr { get; set; }
  173. /// <summary>
  174. /// 星历误差
  175. /// </summary>
  176. public double EphErr { get; set; }
  177. /// <summary>
  178. /// 概率 默认0.5
  179. /// </summary>
  180. public double Pe { get; set; } = 0.5;
  181. }
  182. public static class LeoErrorEllipseHelper
  183. {
  184. private const string errorEllipseDll = @"AddIns\低轨\DLL_GD64.dll";
  185. /// <summary>
  186. /// 低轨双星误差椭圆
  187. /// </summary>
  188. /// <param name="main_eph">主星位置 长度6</param>
  189. /// <param name="neigh_eph">邻星位置 长度6</param>
  190. /// <param name="ref_pos">参考位置 长度3</param>
  191. /// <param name="Select_Point">定位点长度3</param>
  192. /// <param name="dto_err">时差误差(s)</param>
  193. /// <param name="dfo_err">频差误差(Hz)</param>
  194. /// <param name="eph_pos_err"></param>
  195. /// <param name="eph_vel_err"></param>
  196. /// <param name="fu"></param>
  197. /// <param name="Pe">0.5</param>
  198. /// <param name="LOP_Len"></param>
  199. /// <returns></returns>
  200. [DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_DTFO", CallingConvention = CallingConvention.Cdecl)]
  201. public extern static IntPtr Error_Ellipse_DTFO(double[] main_eph, double[] neigh_eph, double[] ref_pos, double[] Select_Point, double dto_err, double dfo_err,
  202. double eph_pos_err, double eph_vel_err, double fu1, double fu2, double Pe, ref int LOP_Len);
  203. /// <summary>
  204. /// 两星一地误差椭圆
  205. /// </summary>
  206. /// <param name="main_eph">主星位置 长度6</param>
  207. /// <param name="neigh_eph">邻星位置 长度6</param>
  208. /// <param name="cdbAnt">超短波 长度3</param>
  209. /// <param name="refStation">参考站 长度3</param>
  210. /// <param name="Select_Point">定位点 长度3</param>
  211. /// <param name="dto_err">时差误差(s)</param>
  212. /// <param name="eph_err"></param>
  213. /// <param name="Pe">0.5</param>
  214. /// <param name="LOP_Len"></param>
  215. /// <returns></returns>
  216. [DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_2X1D", CallingConvention = CallingConvention.Cdecl)]
  217. public extern static IntPtr Error_Ellipse_2X1D(double[] main_eph, double[] neigh_eph, double[] cdbAnt, double[] refStation, double[] Select_Point, double dto_err,
  218. double eph_err, double Pe, ref int LOP_Len);
  219. /// <summary>
  220. /// 单星误差椭圆
  221. /// </summary>
  222. /// <param name="main_eph"></param>
  223. /// <param name="neigh_eph1"></param>
  224. /// <param name="neigh_eph2"></param>
  225. /// <param name="Select_Point"></param>
  226. /// <param name="dfo_err"></param>
  227. /// <param name="eph_pos_err"></param>
  228. /// <param name="eph_vel_err"></param>
  229. /// <param name="fu"></param>
  230. /// <param name="Pe"></param>
  231. /// <param name="LOP_Len"></param>
  232. /// <returns></returns>
  233. [DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_2DFO", CallingConvention = CallingConvention.Cdecl)]
  234. public extern static IntPtr Error_Ellipse_2DFO(double[] main_eph, double[] neigh_eph1, double[] neigh_eph2, double[] Select_Point, double dfo_err, double eph_pos_err, double eph_vel_err, double fu, double Pe,
  235. ref int LOP_Len);
  236. [DllImport(errorEllipseDll, CallingConvention = CallingConvention.Cdecl)]
  237. public static extern void freeBuff(IntPtr buf);
  238. public static ErrEllipseResDto ErrorEllipseLeoX2(ErrorEllipseX2Option opt, bool outputErrPoint)
  239. {
  240. int LOP_Len = 0;
  241. IntPtr LOP_ValuePtr = Error_Ellipse_DTFO(
  242. opt.MsEph,
  243. opt.NsEph,
  244. opt.RefGeod,
  245. opt.SelectPoint,
  246. opt.DtoErr,
  247. opt.DfoErr,
  248. opt.EphPosErr,
  249. opt.EphVelErr,
  250. opt.fu1, opt.fu2, opt.Pe, ref LOP_Len);
  251. return ParseResult(LOP_ValuePtr, LOP_Len, outputErrPoint);
  252. }
  253. public static ErrEllipseResDto ErrorEllipseLeoX3(ErrorEllipseX3Option opt, bool outputErrPoint)
  254. {
  255. #warning 未提供低轨三星误差椭圆算法
  256. int LOP_Len = 0;
  257. IntPtr LOP_ValuePtr = Error_Ellipse_DTFO(
  258. opt.MsEph,
  259. opt.NsEph1,
  260. opt.RefGeod,
  261. opt.SelectPoint,
  262. opt.DtoErr,
  263. opt.DfoErr,
  264. opt.EphPosErr,
  265. opt.EphVelErr,
  266. opt.fu1, opt.fu2, opt.Pe, ref LOP_Len);
  267. return ParseResult(LOP_ValuePtr, LOP_Len, outputErrPoint);
  268. }
  269. public static ErrEllipseResDto ErrorEllipse2X1D(ErrorEllipse2X1DOption opt, bool outputErrPoint)
  270. {
  271. int LOP_Len = 0;
  272. IntPtr LOP_ValuePtr = Error_Ellipse_2X1D(
  273. opt.MsEph,
  274. opt.NsEph,
  275. opt.CDBAnt,
  276. opt.RefGeod,
  277. opt.SelectPoint,
  278. opt.DtoErr,
  279. opt.EphErr,
  280. opt.Pe, ref LOP_Len);
  281. return ParseResult(LOP_ValuePtr, LOP_Len, outputErrPoint);
  282. }
  283. public static ErrEllipseResDto ErrorEllipseLeoX1(ErrorEllipseX1Option opt, bool outputErrPoint)
  284. {
  285. int LOP_Len = 0;
  286. IntPtr LOP_ValuePtr = Error_Ellipse_2DFO(
  287. opt.MsEph,
  288. opt.NsEph1,
  289. opt.NsEph2,
  290. opt.SelectPoint,
  291. opt.DfoErr,
  292. opt.EphPosErr,
  293. opt.EphVelErr,
  294. opt.fu, opt.Pe, ref LOP_Len);
  295. return ParseResult(LOP_ValuePtr, LOP_Len,outputErrPoint);
  296. }
  297. private static ErrEllipseResDto ParseResult(IntPtr LOP_ValuePtr, int LOP_Len, bool outputErrPoint)
  298. {
  299. double[] LOP_Value = new double[LOP_Len];
  300. if (LOP_Len > 0)
  301. {
  302. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  303. }
  304. #warning 低轨多星误差椭圆是否包含长轴、短轴、倾角
  305. ErrEllipseResDto res = new ErrEllipseResDto();
  306. res.LongRadius = LOP_Value[LOP_Value.Length - 3];
  307. res.ShortRadius = LOP_Value[LOP_Value.Length - 2];
  308. res.DipAngle = LOP_Value[LOP_Value.Length - 1];
  309. if (outputErrPoint)
  310. {
  311. int count = LOP_Value.Length - 3;
  312. for (int i = 0; i < count; i += 2)//13 ---01 23 45 67 89
  313. {
  314. res.GeoPoints.Add(new GeoPoint()
  315. {
  316. Lon = LOP_Value[i],
  317. Lat = LOP_Value[i + 1],
  318. });
  319. }
  320. }
  321. return res;
  322. }
  323. }
  324. }