ErrorEllipseHelper.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. namespace XdCxRhDW.Api
  8. {
  9. public class ErrorEllipseDTFOTSOption
  10. {
  11. /// <summary>
  12. /// 主星星历
  13. /// </summary>
  14. public double[] MsEph { get; set; }
  15. /// <summary>
  16. /// 邻星星历
  17. /// </summary>
  18. public double[] NsEph { get; set; }
  19. /// <summary>
  20. /// 参考站位置
  21. /// </summary>
  22. public double[] RefGeod { get; set; }
  23. /// <summary>
  24. /// 定位点
  25. /// </summary>
  26. public double[] SelectPoint { get; set; }
  27. /// <summary>
  28. /// 时差误差(s)
  29. /// </summary>
  30. public double DtoErr { get; set; }
  31. /// <summary>
  32. /// 频差误差(Hz)
  33. /// </summary>
  34. public double DfoErr { get; set; }
  35. /// <summary>
  36. /// 星历位置误差
  37. /// </summary>
  38. public double EphPosErr { get; set; }
  39. /// <summary>
  40. ///星历速度误差
  41. /// </summary>
  42. public double EphVelErr { get; set; }
  43. /// <summary>
  44. /// 上行频点1(Hz)
  45. /// </summary>
  46. public double fu1 { get; set; }
  47. /// <summary>
  48. /// 上行频点2(Hz)
  49. /// </summary>
  50. public double fu2 { get; set; }
  51. /// <summary>
  52. /// 概率 默认0.5
  53. /// </summary>
  54. public double Pe { get; set; } = 0.5;
  55. }
  56. public class ErrorEllipseDTO2X1DOption
  57. {
  58. /// <summary>
  59. /// 主星星历
  60. /// </summary>
  61. public double[] MsEph { get; set; }
  62. /// <summary>
  63. /// 邻星星历
  64. /// </summary>
  65. public double[] NsEph { get; set; }
  66. /// <summary>
  67. /// 超短波位置
  68. /// </summary>
  69. public double[] CDBAnt { get; set; }
  70. /// <summary>
  71. /// 参考站位置
  72. /// </summary>
  73. public double[] RefGeod { get; set; }
  74. /// <summary>
  75. /// 定位点
  76. /// </summary>
  77. public double[] SelectPoint { get; set; }
  78. /// <summary>
  79. /// 时差误差(s)
  80. /// </summary>
  81. public double DtoErr { get; set; }
  82. /// <summary>
  83. /// 星历误差
  84. /// </summary>
  85. public double EphErr { get; set; }
  86. /// <summary>
  87. /// 概率 默认0.5
  88. /// </summary>
  89. public double Pe { get; set; } = 0.5;
  90. }
  91. public class ErrorEllipseDTO1XOption
  92. {
  93. /// <summary>
  94. /// 第一时刻星历
  95. /// </summary>
  96. public double[] MsEph { get; set; }
  97. /// <summary>
  98. ///第二时刻星历
  99. /// </summary>
  100. public double[] NsEph1 { get; set; }
  101. /// <summary>
  102. /// 第三时刻星历
  103. /// </summary>
  104. public double[] NsEph2 { get; set; }
  105. /// <summary>
  106. /// 定位点
  107. /// </summary>
  108. public double[] SelectPoint { get; set; }
  109. /// <summary>
  110. /// 频差误差(Hz)
  111. /// </summary>
  112. public double DfoErr { get; set; }
  113. /// <summary>
  114. /// 星历位置误差
  115. /// </summary>
  116. public double EphPosErr { get; set; }
  117. /// <summary>
  118. ///星历速度误差
  119. /// </summary>
  120. public double EphVelErr { get; set; }
  121. /// <summary>
  122. /// 上行频点(Hz)
  123. /// </summary>
  124. public double fu { get; set; }
  125. /// <summary>
  126. /// 概率 默认0.5
  127. /// </summary>
  128. public double Pe { get; set; } = 0.5;
  129. }
  130. public static class ErrorEllipseHelper
  131. {
  132. private const string errorEllipseDll = @"Api\低轨\GDOP\DLL_GD64.dll";
  133. /// <summary>
  134. /// 低轨双星误差椭圆
  135. /// </summary>
  136. /// <param name="main_eph">主星位置 长度6</param>
  137. /// <param name="neigh_eph">邻星位置 长度6</param>
  138. /// <param name="ref_pos">参考位置 长度3</param>
  139. /// <param name="Select_Point">定位点长度3</param>
  140. /// <param name="dto_err">时差误差(s)</param>
  141. /// <param name="dfo_err">频差误差(Hz)</param>
  142. /// <param name="eph_pos_err"></param>
  143. /// <param name="eph_vel_err"></param>
  144. /// <param name="fu"></param>
  145. /// <param name="Pe">0.5</param>
  146. /// <param name="LOP_Len"></param>
  147. /// <returns></returns>
  148. [DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_DTFO", CallingConvention = CallingConvention.Cdecl)]
  149. 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,
  150. double eph_pos_err, double eph_vel_err, double fu1, double fu2, double Pe, ref int LOP_Len);
  151. /// <summary>
  152. /// 两星一地误差椭圆
  153. /// </summary>
  154. /// <param name="main_eph">主星位置 长度6</param>
  155. /// <param name="neigh_eph">邻星位置 长度6</param>
  156. /// <param name="cdbAnt">超短波 长度3</param>
  157. /// <param name="refStation">参考站 长度3</param>
  158. /// <param name="Select_Point">定位点 长度3</param>
  159. /// <param name="dto_err">时差误差(s)</param>
  160. /// <param name="eph_err"></param>
  161. /// <param name="Pe">0.5</param>
  162. /// <param name="LOP_Len"></param>
  163. /// <returns></returns>
  164. [DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_2X1D", CallingConvention = CallingConvention.Cdecl)]
  165. public extern static IntPtr Error_Ellipse_2X1D(double[] main_eph, double[] neigh_eph, double[] cdbAnt, double[] refStation, double[] Select_Point, double dto_err,
  166. double eph_err, double Pe, ref int LOP_Len);
  167. /// <summary>
  168. /// 单星误差椭圆
  169. /// </summary>
  170. /// <param name="main_eph"></param>
  171. /// <param name="neigh_eph1"></param>
  172. /// <param name="neigh_eph2"></param>
  173. /// <param name="Select_Point"></param>
  174. /// <param name="dfo_err"></param>
  175. /// <param name="eph_pos_err"></param>
  176. /// <param name="eph_vel_err"></param>
  177. /// <param name="fu"></param>
  178. /// <param name="Pe"></param>
  179. /// <param name="LOP_Len"></param>
  180. /// <returns></returns>
  181. [DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_2DFO", CallingConvention = CallingConvention.Cdecl)]
  182. 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,
  183. ref int LOP_Len);
  184. [DllImport(errorEllipseDll, CallingConvention = CallingConvention.Cdecl)]
  185. public static extern void freeBuff(IntPtr buf);
  186. public static IEnumerable<(double lon, double lat)> ErrorEllipseLeoX2(ErrorEllipseDTFOTSOption opt)
  187. {
  188. List<DtoLinePoint> list = new List<DtoLinePoint>();
  189. int LOP_Len = 0;
  190. IntPtr LOP_ValuePtr = Error_Ellipse_DTFO(
  191. opt.MsEph,
  192. opt.NsEph,
  193. opt.RefGeod,
  194. opt.SelectPoint,
  195. opt.DtoErr,
  196. opt.DfoErr,
  197. opt.EphPosErr,
  198. opt.EphVelErr,
  199. opt.fu1, opt.fu2, opt.Pe, ref LOP_Len);
  200. return ParseResult(LOP_ValuePtr, LOP_Len);
  201. }
  202. public static IEnumerable<(double lon, double lat)> ErrorEllipse2X1D(ErrorEllipseDTO2X1DOption opt)
  203. {
  204. int LOP_Len = 0;
  205. IntPtr LOP_ValuePtr = Error_Ellipse_2X1D(
  206. opt.MsEph,
  207. opt.NsEph,
  208. opt.CDBAnt,
  209. opt.RefGeod,
  210. opt.SelectPoint,
  211. opt.DtoErr,
  212. opt.EphErr,
  213. opt.Pe, ref LOP_Len);
  214. return ParseResult(LOP_ValuePtr, LOP_Len);
  215. }
  216. public static IEnumerable<(double lon, double lat)> ErrorEllipseLeoX1(ErrorEllipseDTO1XOption opt)
  217. {
  218. int LOP_Len = 0;
  219. IntPtr LOP_ValuePtr = Error_Ellipse_2DFO(
  220. opt.MsEph,
  221. opt.NsEph1,
  222. opt.NsEph2,
  223. opt.SelectPoint,
  224. opt.DfoErr,
  225. opt.EphPosErr,
  226. opt.EphVelErr,
  227. opt.fu, opt.Pe, ref LOP_Len);
  228. return ParseResult(LOP_ValuePtr, LOP_Len);
  229. }
  230. private static IEnumerable<(double lon, double lat)> ParseResult(IntPtr LOP_ValuePtr, int LOP_Len)
  231. {
  232. List<DtoLinePoint> list = new List<DtoLinePoint>();
  233. double[] LOP_Value = new double[LOP_Len];
  234. if (LOP_Len > 0)
  235. {
  236. Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
  237. int len = LOP_Len / 2;
  238. for (int i = 0; i < len; i++)
  239. {
  240. int temp = i * 2;
  241. list.Add(new DtoLinePoint()
  242. {
  243. Lon = LOP_Value[temp],
  244. Lat = LOP_Value[temp + 1]
  245. });
  246. }
  247. }
  248. var Lines = list.Select(p => (p.Lon, p.Lat));
  249. return Lines;
  250. }
  251. }
  252. }