PosApi.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using XdCxRhDW.Entity;
  9. using XdCxRhDW.Framework;
  10. namespace XdCxRhDW.Api
  11. {
  12. /// <summary>
  13. ///TODO 定位算法接口.在这里调用罗博士的算法库
  14. /// </summary>
  15. public static class PosApi
  16. {
  17. //置信度统计次数
  18. private static int confidenceCount = 10000;
  19. //置信度有效距离(m)
  20. private static int confidenceDistance = 10000;
  21. #region cpp dll Interop
  22. //两星一地和三星解析定位算法(精度差、速度快,适用于置信度等统计时的多次调用)
  23. private const string gzPos = @"AddIns\定位\DLL_GZDW.dll";
  24. //一星一地测向带参定位
  25. private const string XDCX = @"AddIns\定位\DLL_DTO_DOA_DW.dll";
  26. //三星双时差带参、三星双时差无参、三星双频差带参、双星时频差带参、两星一地无参定位及时差线、一星两地
  27. private const string OtherPos = @"AddIns\定位\Position-New.dll";//DLL_11J_DW
  28. [DllImport(gzPos, EntryPoint = "DW_Analysis", CallingConvention = CallingConvention.Cdecl)]//两星一地和三星的解析定位算法(精度差、速度快)
  29. private extern static void DW_Analysis(double[] mainSatXYZ, double[] adja1XYZ, double[] adja2XYZ, double[] refStation, double tarDto1, double tarDto2, double refDto1, double refDto2, double[] posRes, int flag);
  30. [DllImport(XDCX, EntryPoint = "XD_CX_DW", CallingConvention = CallingConvention.Cdecl)]//一星一地测向带参
  31. private extern static void X1D1_Pos20240305_Core(double[] mainSat, double[] satStation, double[] cdbStation, double[] cxStation, double[] refStation, double[] zone, double theta, double tarDto, double refDto, double[] res);
  32. [DllImport(OtherPos, EntryPoint = "SC_2X1D_DW", CallingConvention = CallingConvention.Cdecl)]//两星一地带参
  33. private extern static void X2D1_Pos20240305_Core(double[] mainSat, double[] adjaSat, double[] cdbStation, double[] satStation1, double[] satStation2, double[] satStation3, double[] satStation4,
  34. double[] satStation5, double[] refStation, double[] zone, double tarSxDto, double tarXdDto, double samp_main_dto, double samp_neigh_dto, double[] res);
  35. [DllImport(OtherPos, EntryPoint = "XingDi_2X1D_DW_NoRef", CallingConvention = CallingConvention.Cdecl)]//两星一地无参
  36. private extern static void X2D1_PosNoRef20240305_Core(double[] mainSat, double[] adjaSat, double[] cdbStation, double[] mainSatTarStation, double[] adjaSat1TarStation, double[] adjaSat2TarStation
  37. , double[] zone, double tarSxDto, double tarXdDto, double[] res);
  38. [DllImport(OtherPos, EntryPoint = "SanXing_DW", CallingConvention = CallingConvention.Cdecl)]//三星双时差带参
  39. private extern static void X3_Pos20240305_Core(double[] mainSat, double[] adjaSat1, double[] adjaSat2, double[] mainSatTarStation, double[] adjaSat1TarStation, double[] adjaSat2TarStation
  40. , double[] mainSatRefStation, double[] adjaSat1RefStation, double[] adjaSat2RefStation, double[] refStation, double[] zone, double tarDto1, double tarDto2, double refDto1, double refDto2, double[] res);
  41. [DllImport(OtherPos, EntryPoint = "SanXing_DW_NoRef", CallingConvention = CallingConvention.Cdecl)]//三星双时差无参
  42. private extern static void X3_PosNoRef20240305_Core(double[] mainSat, double[] adjaSat1, double[] adjaSat2, double[] mainSatTarStation, double[] adjaSat1TarStation, double[] adjaSat2TarStation
  43. , double[] zone, double tarDto1, double tarDto2, double[] res);
  44. [DllImport(OtherPos, EntryPoint = "TriStar_2DFO_DW", CallingConvention = CallingConvention.Cdecl)]//三星双频差带参
  45. private extern static void X3_PosTwoDfo20240305_Core(double[] mainSat, double[] adjaSat1, double[] adjaSat2, double[] mainSatTarStation, double[] adjaSat1TarStation, double[] adjaSat2TarStation
  46. , double[] refStation, double[] zone, double tarDfo1, double tarDfo2, double refDfo1, double refDfo2, double fu1, double fd1, double fu2, double fd2, double[] res);
  47. [DllImport(OtherPos, EntryPoint = "TwoStar_DTFO_DW", CallingConvention = CallingConvention.Cdecl)]//双星时频差带参
  48. private extern static void X2_Pos20240305_Core(double[] mainSat, double[] adjaSat, double[] mainSatTarStation, double[] adjaSatTarStation, double[] refStation, double[] zone
  49. , double tarDto, double tarDfo, double refDto, double refDfo, double fu1, double fd1, double fu2, double fd2, double[] res);
  50. #endregion
  51. /// <summary>
  52. /// 一星一地带参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  53. /// </summary>
  54. /// <param name="cgRes">参估结果</param>
  55. /// <param name="sRes">站点信息</param>
  56. /// <param name="cxRes">测向结果</param>
  57. /// <param name="CalcConfidence">是否计算置信度</param>
  58. /// <returns></returns>
  59. public static double[] X1D1_Pos(CgRes cgRes, StationRes sRes, CxRes cxRes, bool CalcConfidence = false)
  60. {
  61. if (cgRes.DtoCdb.Value == 0) return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  62. double[] mainSat = new double[3] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value };
  63. double[] satStation = new double[3] { sRes.SatTxLon, sRes.SatTxLat, 0 };
  64. double[] cdbStation = new double[3] { sRes.CdbTxLon.Value, sRes.CdbTxLat.Value, 0 };
  65. double[] cxStation = new double[3] { sRes.CxLon.Value, sRes.CxLat.Value, 0 };
  66. double[] refStation = new double[3] { sRes.RefLon.Value, sRes.RefLat.Value, 0 };
  67. double dtoCdb = cgRes.DtoCdb.Value / 1e6;
  68. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  69. double theta = cxRes.Fx;//单位°
  70. double[] res = new double[6];
  71. var ybDto1 = cgRes.YbMainDto.Value / 1e6;
  72. X1D1_Pos20240305_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, dtoCdb, ybDto1, res);
  73. var posRes = ConvertToGeoPoint(res);
  74. if (CalcConfidence && IsGeoPoint2(posRes))
  75. {
  76. int succeedCount = 0;
  77. for (int i = 0; i < confidenceCount; i++)
  78. {
  79. var mainSatNew = new double[3]
  80. {
  81. cgRes.MainX.Value+RandomHelper.Normal(0,200),
  82. cgRes.MainY.Value+RandomHelper.Normal(0,200),
  83. cgRes.MainZ.Value+RandomHelper.Normal(0,200)
  84. };
  85. var dtoCdbNew = (dtoCdb * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  86. var ybDtoNew = (ybDto1 * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  87. var thetaNew = theta + RandomHelper.Normal(0, 0.4);//单位°
  88. X1D1_Pos20240305_Core(mainSatNew, satStation, cdbStation, cxStation, refStation, zone, thetaNew, dtoCdbNew, ybDtoNew, res);
  89. var posResNew = ConvertToGeoPoint(res);
  90. if (IsGeoPoint2(posResNew))
  91. {
  92. var distance = PhysicsHelper.DistanceGeo((posRes[0], posRes[1], 0), (posResNew[0], posResNew[1], 0));
  93. if (distance <= confidenceDistance)
  94. {
  95. succeedCount++;
  96. }
  97. }
  98. }
  99. posRes[6] = (int)(succeedCount / (double)confidenceCount * 100);
  100. }
  101. return posRes;
  102. }
  103. /// <summary>
  104. /// 两星一地带参解析定位(精度差速度快,主要用于置信度分析等需要多次调用的情况)
  105. /// </summary>
  106. /// <param name="cgRes"></param>
  107. /// <param name="sRes"></param>
  108. /// <returns></returns>
  109. public static double[] X2D1_GzPos(CgRes cgRes, StationRes sRes)
  110. {
  111. if (cgRes.Dto1.Value == 0 || cgRes.DtoCdb.Value == 0)
  112. {
  113. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  114. }
  115. double[] mainSat = new double[3] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value };
  116. double[] adjaSat = new double[3] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value };
  117. double[] cdbStation = new double[3] { sRes.CdbTxLon.Value, sRes.CdbTxLat.Value, 0 };
  118. double[] refStation = new double[3] { sRes.RefLon.Value, sRes.RefLat.Value, 0 };
  119. double dto1 = cgRes.Dto1.Value / 1e6;
  120. double dtoCdb = cgRes.DtoCdb.Value / 1e6;
  121. double ybDto1 = cgRes.YbMainDto.Value / 1e6;
  122. double ybDto2 = cgRes.YbAdja1Dto.Value / 1e6;
  123. double ybDto = ybDto1 - ybDto2;
  124. double[] posRes = new double[3];
  125. DW_Analysis(mainSat, adjaSat, cdbStation, refStation, dto1, -dtoCdb, ybDto, -ybDto1, posRes, 1);
  126. return posRes;
  127. }
  128. /// <summary>
  129. /// 三星双时差带参解析定位(精度差速度快,主要用于置信度分析等需要多次调用的情况)
  130. /// </summary>
  131. /// <param name="cgRes"></param>
  132. /// <param name="sRes"></param>
  133. /// <returns></returns>
  134. public static double[] X3Dto_GzPos(CgRes cgRes, StationRes sRes)
  135. {
  136. if (cgRes.Dto1.Value == 0 || cgRes.Dto2.Value == 0)
  137. {
  138. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  139. }
  140. double[] mainSat = new double[3] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value };
  141. double[] adja1Sat = new double[3] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value };
  142. double[] adja2Sat = new double[3] { cgRes.Adja2X.Value, cgRes.Adja2Y.Value, cgRes.Adja2Z.Value };
  143. double[] refStation = new double[3] { sRes.RefLon.Value, sRes.RefLat.Value, 0 };
  144. double dto1 = cgRes.Dto1.Value / 1e6;
  145. double dto2 = cgRes.Dto2.Value / 1e6;
  146. double ybDto1 = cgRes.YbMainDto.Value / 1e6;
  147. double ybDto2 = cgRes.YbAdja1Dto.Value / 1e6;
  148. double ybDto3 = cgRes.YbAdja2Dto.Value / 1e6;
  149. double refDto1 = ybDto1 - ybDto2;
  150. double refDto2 = ybDto1 - ybDto3;
  151. double[] posRes = new double[3];
  152. DW_Analysis(mainSat, adja1Sat, adja2Sat, refStation, dto1, dto2, refDto1, refDto2, posRes, 0);
  153. return posRes;
  154. }
  155. /// <summary>
  156. /// 两星一地带参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  157. /// </summary>
  158. /// <param name="cgRes">参估结果</param>
  159. /// <param name="sRes">站点信息</param>
  160. /// <param name="CalcConfidence">是否计算置信度</param>
  161. /// <returns></returns>
  162. public static double[] X2D1_Pos(CgRes cgRes, StationRes sRes, bool CalcConfidence = false)
  163. {
  164. if (cgRes.Dto1.Value == 0 || cgRes.DtoCdb.Value == 0)
  165. {
  166. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  167. }
  168. double[] mainSat = new double[3] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value };
  169. double[] adjaSat = new double[3] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value };
  170. double[] satStation = new double[3] { sRes.SatTxLon, sRes.SatTxLat, 0 };
  171. double[] cdbStation = new double[3] { sRes.CdbTxLon.Value, sRes.CdbTxLat.Value, 0 };
  172. double[] refStation = new double[3] { sRes.RefLon.Value, sRes.RefLat.Value, 0 };
  173. double dto1 = cgRes.Dto1.Value / 1e6;
  174. double dtoCdb = cgRes.DtoCdb.Value / 1e6;
  175. double ybDto1 = cgRes.YbMainDto.Value / 1e6;
  176. double ybDto2 = cgRes.YbAdja1Dto.Value / 1e6;
  177. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  178. double[] res = new double[6];
  179. X2D1_Pos20240305_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, dto1, dtoCdb, ybDto1, ybDto2, res);
  180. ConvertToGeoPoint(res);
  181. var posRes = ConvertToGeoPoint(res);//精确搜索值
  182. if (CalcConfidence && IsGeoPoint2(posRes))
  183. {
  184. var posResGz = X2D1_GzPos(cgRes, sRes);
  185. if (IsGeoPoint2(posResGz))
  186. {
  187. int succeedCount = 0;
  188. var cgResNew = cgRes.Clone();
  189. for (int i = 0; i < confidenceCount; i++)
  190. {
  191. cgResNew.MainX = cgRes.MainX + RandomHelper.Normal(0, 500);
  192. cgResNew.MainY = cgRes.MainY + RandomHelper.Normal(0, 500);
  193. cgResNew.MainZ = cgRes.MainZ + RandomHelper.Normal(0, 500);
  194. cgResNew.Adja1X = cgRes.Adja1X + RandomHelper.Normal(0, 500);
  195. cgResNew.Adja1Y = cgRes.Adja1Y + RandomHelper.Normal(0, 500);
  196. cgResNew.Adja1Z = cgRes.Adja1Z + RandomHelper.Normal(0, 500);
  197. cgResNew.Dto1 = (cgRes.Dto1 * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  198. cgResNew.DtoCdb = (cgRes.DtoCdb * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  199. cgResNew.YbMainDto = (cgRes.YbMainDto * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  200. cgResNew.YbAdja1Dto = (cgRes.YbAdja1Dto * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  201. res = X2D1_GzPos(cgResNew, sRes);
  202. var posResNew = ConvertToGeoPoint(res);
  203. if (IsGeoPoint2(posResNew))
  204. {
  205. var distance = PhysicsHelper.DistanceGeo((posResGz[0], posResGz[1], 0), (posResNew[0], posResNew[1], 0));
  206. if (distance <= confidenceDistance)
  207. {
  208. succeedCount++;
  209. }
  210. }
  211. }
  212. posRes[6] = (int)(succeedCount / (double)confidenceCount * 100);
  213. }
  214. else
  215. {
  216. posRes[6] = 0;
  217. }
  218. }
  219. return posRes;
  220. }
  221. /// <summary>
  222. /// 两星一地无参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  223. /// </summary>
  224. /// <param name="cgRes">参估结果</param>
  225. /// <param name="sRes">站点信息</param>
  226. /// <param name="CalcConfidence">是否计算置信度</param>
  227. /// <returns></returns>
  228. public static double[] X2D1_PosNoRef(CgRes cgRes, StationRes sRes, bool CalcConfidence = false)
  229. {
  230. if (cgRes.Dto1.Value == 0 || cgRes.DtoCdb.Value == 0)
  231. {
  232. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  233. }
  234. double[] mainSat = new double[3] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value };
  235. double[] adjaSat = new double[3] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value };
  236. double[] satStation = new double[3] { sRes.SatTxLon, sRes.SatTxLat, 0 };
  237. double[] cdbStation = new double[3] { sRes.CdbTxLon.Value, sRes.CdbTxLat.Value, 0 };
  238. double dto1 = cgRes.Dto1.Value / 1e6;
  239. double dtoCdb = cgRes.DtoCdb.Value / 1e6;
  240. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  241. double[] res = new double[6];
  242. X2D1_PosNoRef20240305_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, zone, dto1, dtoCdb, res);
  243. ConvertToGeoPoint(res);
  244. var posRes = ConvertToGeoPoint(res);
  245. if (CalcConfidence && IsGeoPoint2(posRes))
  246. {
  247. int succeedCount = 0;
  248. for (int i = 0; i < confidenceCount; i++)
  249. {
  250. var mainSatNew = new double[3]
  251. {
  252. cgRes.MainX.Value+RandomHelper.Normal(0,200),
  253. cgRes.MainY.Value+RandomHelper.Normal(0,200),
  254. cgRes.MainZ.Value+RandomHelper.Normal(0,200)
  255. };
  256. var adjaSatNew = new double[3]
  257. {
  258. cgRes.Adja1X.Value+RandomHelper.Normal(0,200),
  259. cgRes.Adja1Y.Value+RandomHelper.Normal(0,200),
  260. cgRes.Adja1Z.Value+RandomHelper.Normal(0,200)
  261. };
  262. var dto1New = (dto1 * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  263. var dtoCdbNew = (dtoCdb * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  264. X2D1_PosNoRef20240305_Core(mainSatNew, adjaSatNew, cdbStation, satStation, satStation, satStation, zone, dto1New, dtoCdbNew, res);
  265. var posResNew = ConvertToGeoPoint(res);
  266. if (IsGeoPoint2(posResNew))
  267. {
  268. var distance = PhysicsHelper.DistanceGeo((posRes[0], posRes[1], 0), (posResNew[0], posResNew[1], 0));
  269. if (distance <= confidenceDistance)
  270. {
  271. succeedCount++;
  272. }
  273. }
  274. }
  275. posRes[6] = (int)(succeedCount / (double)confidenceCount * 100);
  276. }
  277. return posRes;
  278. }
  279. public static double[] X2D1_PosNoRef_ZL(double[] posRes, CgRes cgRes, StationRes sRes)
  280. {
  281. if (cgRes.Dto1.Value == 0 || cgRes.DtoCdb.Value == 0)
  282. {
  283. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  284. }
  285. double startLon = (int)sRes.CdbTxLon.Value - 20;
  286. double endLon = (int)sRes.CdbTxLon.Value + 20;
  287. double startLat = (int)sRes.CdbTxLat.Value - 20;
  288. double endLat = (int)sRes.CdbTxLat.Value + 20;
  289. List<(double, double, double, double)> list = new List<(double, double, double, double)>();
  290. var recXYZ = PhysicsHelper.GeoToEcef((sRes.SatTxLon, sRes.SatTxLat, 0));
  291. var cdbXYZ = PhysicsHelper.GeoToEcef((sRes.CdbTxLon.Value, sRes.CdbTxLat.Value, 0));
  292. for (double lon = startLon; lon < endLon; lon += 0.0001)
  293. {
  294. int flag = 0;
  295. for (double lat = startLat; lat < endLat; lat += 0.0001)
  296. {
  297. var posXYZ = PhysicsHelper.GeoToEcef((lon, lat, 0));
  298. //目标-主星-接收站的时间(us)
  299. var dt1 = PhysicsHelper.Dto(posXYZ, (cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value), recXYZ) * 1e6;
  300. //目标-超短站的时间(us)
  301. var dt3 = PhysicsHelper.Dto(posXYZ, cdbXYZ) * 1e6;
  302. var dto2 = Math.Abs(dt1 - dt3 - cgRes.DtoCdb.Value);
  303. if (dto2 > 100)
  304. {
  305. lat += 1;
  306. if (flag < 1)
  307. flag = 1;
  308. continue;
  309. }
  310. else if (dto2 > 50)
  311. {
  312. lat += 0.5;
  313. if (flag < 2)
  314. flag = 2;
  315. continue;
  316. }
  317. else if (dto2 > 20)
  318. {
  319. lat += 0.2;
  320. if (flag < 3)
  321. flag = 3;
  322. continue;
  323. }
  324. else if (dto2 > 5)
  325. {
  326. lat += 0.1;
  327. if (flag < 4)
  328. flag = 4;
  329. continue;
  330. }
  331. else if (dto2 > 2)
  332. {
  333. lat += 0.02;
  334. if (flag < 5)
  335. flag = 5;
  336. continue;
  337. }
  338. //目标-邻星-接收站的时间(us)
  339. var dt2 = PhysicsHelper.Dto(posXYZ, (cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value), recXYZ) * 1e6;
  340. var dto1 = Math.Abs(dt1 - dt2 - cgRes.Dto1.Value);
  341. //if (dto1 > 100)
  342. //{
  343. // lat += 1;
  344. // if (flag < 1)
  345. // flag = 1;
  346. // continue;
  347. //}
  348. //else if (dto1 > 50)
  349. //{
  350. // lat += 0.5;
  351. // if (flag < 2)
  352. // flag = 2;
  353. // continue;
  354. //}
  355. //else if (dto1 > 20)
  356. //{
  357. // lat += 0.2;
  358. // if (flag < 3)
  359. // flag = 3;
  360. // continue;
  361. //}
  362. //else if (dto1 > 5)
  363. //{
  364. // lat += 0.1;
  365. // if (flag < 4)
  366. // flag = 4;
  367. // continue;
  368. //}
  369. //else if (dto1 > 2)
  370. //{
  371. // lat += 0.02;
  372. // if (flag < 5)
  373. // flag = 5;
  374. // continue;
  375. //}
  376. list.Add((lon, lat, dto1, dto2));
  377. }
  378. if (flag == 1)
  379. lon += 1;
  380. else if (flag == 2)
  381. lon += 0.5;
  382. else if (flag == 3)
  383. lon += 0.2;
  384. else if (flag == 4)
  385. lon += 0.1;
  386. else if (flag == 5)
  387. lon += 0.02;
  388. }
  389. var val = list.OrderBy(p => p.Item3 + p.Item4).First();
  390. return new double[7] { val.Item1, val.Item2, 0, 999, 999, 0, -1 };
  391. }
  392. /// <summary>
  393. /// 融合定位带参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  394. /// </summary>
  395. /// <param name="cgRes">参估结果</param>
  396. /// <param name="sRes">站点信息</param>
  397. /// <param name="cxRes">测向结果</param>
  398. /// <param name="CalcConfidence">是否计算置信度</param>
  399. /// <returns></returns>
  400. public static double[] RH_Pos(CgRes cgRes, StationRes sRes, CxRes cxRes, bool CalcConfidence = false)
  401. {
  402. var res1 = X1D1_Pos(cgRes, sRes, cxRes, CalcConfidence);
  403. var res2 = X2D1_Pos(cgRes, sRes, CalcConfidence);
  404. double[] res = new double[] { 999, 999, 0, 999, 999, 0, 100 };
  405. var p1 = res1.Take(3).ToArray();
  406. var p2 = res1.Skip(3).ToArray();
  407. var p3 = res2.Take(3).ToArray();
  408. var p4 = res2.Skip(3).ToArray();
  409. if (IsGeoPoint(p1) && IsGeoPoint(p2) && IsGeoPoint(p3) && IsGeoPoint(p4))
  410. {
  411. res = new double[7] {
  412. (p1[0] + p3[0]) / 2 + 0.003,
  413. (p1[1] + p3[1]) / 2 - 0.002,
  414. 0,
  415. (p2[0] + p4[0]) / 2 + 0.003,
  416. (p2[1] + p4[1]) / 2 - 0.002,
  417. 0,
  418. (res1[6]+res2[6])/2
  419. };
  420. }
  421. else if (IsGeoPoint(p1) && IsGeoPoint(p3))
  422. {
  423. res = new double[7] {
  424. (p1[0] + p3[0]) / 2 + 0.003,
  425. (p1[1] + p3[1]) / 2 - 0.002,
  426. 0,
  427. 999,
  428. 999,
  429. 0,
  430. (res1[6]+res2[6])/2
  431. };
  432. }
  433. else if (IsGeoPoint(p1) && IsGeoPoint(p2))
  434. {
  435. res = new double[7]
  436. {
  437. p1[0] + 0.003,
  438. p1[1] - 0.002,
  439. 0,
  440. p2[0] + 0.003,
  441. p2[1] - 0.002,
  442. 0,
  443. (res1[6]+res2[6])/2
  444. };
  445. }
  446. else if (IsGeoPoint(p3) && IsGeoPoint(p4))
  447. {
  448. res = new double[7]
  449. {
  450. p3[0] + 0.003,
  451. p3[1] - 0.002,
  452. 0,
  453. p4[0] + 0.003,
  454. p4[1] - 0.002,
  455. 0,
  456. (res1[6]+res2[6])/2
  457. };
  458. }
  459. return res;
  460. }
  461. /// <summary>
  462. /// 三星双时差带参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  463. /// </summary>
  464. /// <param name="cgRes">参估结果</param>
  465. /// <param name="sRes">站点信息</param>
  466. /// <param name="CalcConfidence">是否计算置信度</param>
  467. /// <returns></returns>
  468. public static double[] X3_Pos(CgRes cgRes, StationRes sRes, bool CalcConfidence = false)
  469. {
  470. if (cgRes.Dto1.Value == 0 || cgRes.Dto2.Value == 0)
  471. {
  472. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  473. }
  474. if (cgRes.Dto1.Value == 0 || cgRes.Dto2.Value == 0) return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  475. double[] mainSat = new double[3] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value };
  476. double[] adjaSat1 = new double[3] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value };
  477. double[] adjaSat2 = new double[3] { cgRes.Adja2X.Value, cgRes.Adja2Y.Value, cgRes.Adja2Z.Value };
  478. double[] satStation = new double[3] { sRes.SatTxLon, sRes.SatTxLat, 0 };
  479. double[] refStation = new double[3] { sRes.RefLon.Value, sRes.RefLat.Value, 0 };
  480. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  481. var tarDto1 = cgRes.Dto1.Value / 1e6;
  482. var tarDto2 = cgRes.Dto2.Value / 1e6;
  483. var refDto1 = (cgRes.YbMainDto.Value - cgRes.YbAdja1Dto.Value) / 1e6;
  484. var refDto2 = (cgRes.YbMainDto.Value - cgRes.YbAdja2Dto.Value) / 1e6;
  485. double[] res = new double[6];
  486. X3_Pos20240305_Core(mainSat, adjaSat1, adjaSat2, satStation, satStation, satStation, satStation,
  487. satStation, satStation, refStation, zone, tarDto1, tarDto2, refDto1, refDto2, res);
  488. var posRes = ConvertToGeoPoint(res);//精确搜索值
  489. if (CalcConfidence && IsGeoPoint2(posRes))
  490. {
  491. var posResGz = X3Dto_GzPos(cgRes, sRes);
  492. if (IsGeoPoint2(posResGz))
  493. {
  494. int succeedCount = 0;
  495. var cgResNew = cgRes.Clone();
  496. for (int i = 0; i < confidenceCount; i++)
  497. {
  498. cgResNew.MainX = cgRes.MainX + RandomHelper.Normal(0, 500);
  499. cgResNew.MainY = cgRes.MainY + RandomHelper.Normal(0, 500);
  500. cgResNew.MainZ = cgRes.MainZ + RandomHelper.Normal(0, 500);
  501. cgResNew.Adja1X = cgRes.Adja1X + RandomHelper.Normal(0, 500);
  502. cgResNew.Adja1Y = cgRes.Adja1Y + RandomHelper.Normal(0, 500);
  503. cgResNew.Adja1Z = cgRes.Adja1Z + RandomHelper.Normal(0, 500);
  504. cgResNew.Adja2X = cgRes.Adja2X + RandomHelper.Normal(0, 500);
  505. cgResNew.Adja2Y = cgRes.Adja2Y + RandomHelper.Normal(0, 500);
  506. cgResNew.Adja2Z = cgRes.Adja2Z + RandomHelper.Normal(0, 500);
  507. cgResNew.Dto1 = (cgRes.Dto1 * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  508. cgResNew.Dto2 = (cgRes.Dto2 * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  509. cgResNew.YbMainDto = (cgRes.YbMainDto * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  510. cgResNew.YbAdja1Dto = (cgRes.YbAdja1Dto * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  511. cgResNew.YbAdja2Dto = (cgRes.YbAdja2Dto * 1e6 + RandomHelper.Normal(0, 4)) / 1e6;
  512. res = X3Dto_GzPos(cgResNew, sRes);
  513. var posResNew = ConvertToGeoPoint(res);
  514. if (IsGeoPoint2(posResNew))
  515. {
  516. var distance = PhysicsHelper.DistanceGeo((posResGz[0], posResGz[1], 0), (posResNew[0], posResNew[1], 0));
  517. if (distance <= confidenceDistance)
  518. {
  519. succeedCount++;
  520. }
  521. }
  522. }
  523. posRes[6] = (int)(succeedCount / (double)confidenceCount * 100);
  524. }
  525. else
  526. {
  527. posRes[6] = 0;
  528. }
  529. }
  530. return posRes;
  531. }
  532. /// <summary>
  533. /// 三星双时差无参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  534. /// </summary>
  535. /// <param name="cgRes">参估结果</param>
  536. /// <param name="sRes">站点信息</param>
  537. /// <param name="CalcConfidence">是否计算置信度</param>
  538. /// <returns></returns>
  539. public static double[] X3_PosNoRef(CgRes cgRes, StationRes sRes, bool CalcConfidence = false)
  540. {
  541. if (cgRes.Dto1.Value == 0 || cgRes.Dto2.Value == 0)
  542. {
  543. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  544. }
  545. double[] mainSat = new double[3] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value };
  546. double[] adjaSat1 = new double[3] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value };
  547. double[] adjaSat2 = new double[3] { cgRes.Adja2X.Value, cgRes.Adja2Y.Value, cgRes.Adja2Z.Value };
  548. double[] satStation = new double[3] { sRes.SatTxLon, sRes.SatTxLat, 0 };
  549. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  550. var tarDto1 = cgRes.Dto1.Value / 1e6;
  551. var tarDto2 = cgRes.Dto2.Value / 1e6;
  552. double[] res = new double[6];
  553. X3_PosNoRef20240305_Core(mainSat, adjaSat1, adjaSat2, satStation, satStation, satStation, zone, tarDto1, tarDto2, res);
  554. ConvertToGeoPoint(res);
  555. var posRes = ConvertToGeoPoint(res);
  556. if (CalcConfidence && IsGeoPoint2(posRes))
  557. {
  558. int succeedCount = 0;
  559. for (int i = 0; i < confidenceCount; i++)
  560. {
  561. var mainSatNew = new double[3]
  562. {
  563. cgRes.MainX.Value+RandomHelper.Normal(0,200),
  564. cgRes.MainY.Value+RandomHelper.Normal(0,200),
  565. cgRes.MainZ.Value+RandomHelper.Normal(0,200)
  566. };
  567. var adjaSat1New = new double[3]
  568. {
  569. cgRes.Adja1X.Value+RandomHelper.Normal(0,200),
  570. cgRes.Adja1Y.Value+RandomHelper.Normal(0,200),
  571. cgRes.Adja1Z.Value+RandomHelper.Normal(0,200)
  572. };
  573. var adjaSat2New = new double[3]
  574. {
  575. cgRes.Adja2X.Value+RandomHelper.Normal(0,200),
  576. cgRes.Adja2Y.Value+RandomHelper.Normal(0,200),
  577. cgRes.Adja2Z.Value+RandomHelper.Normal(0,200)
  578. };
  579. var tarDto1New = (tarDto1 * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  580. var tarDto2New = (tarDto2 * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  581. X3_PosNoRef20240305_Core(mainSatNew, adjaSat1New, adjaSat2New, satStation, satStation, satStation, zone, tarDto1New, tarDto2New, res);
  582. var posResNew = ConvertToGeoPoint(res);
  583. if (IsGeoPoint2(posResNew))
  584. {
  585. var distance = PhysicsHelper.DistanceGeo((posRes[0], posRes[1], 0), (posResNew[0], posResNew[1], 0));
  586. if (distance <= confidenceDistance)
  587. {
  588. succeedCount++;
  589. }
  590. }
  591. }
  592. posRes[6] = (int)(succeedCount / (double)confidenceCount * 100);
  593. }
  594. return posRes;
  595. }
  596. /// <summary>
  597. /// 三星双频差带参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  598. /// </summary>
  599. /// <param name="cgRes">参估结果</param>
  600. /// <param name="sRes">站点信息</param>
  601. /// <param name="CalcConfidence">是否计算置信度</param>
  602. /// <returns></returns>
  603. public static double[] X3_PosTwoDfo(CgRes cgRes, StationRes sRes, bool CalcConfidence = false)
  604. {
  605. if (cgRes.Dfo1.Value == 0 || cgRes.Dfo2.Value == 0) return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  606. double[] mainSat = new double[6] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value, cgRes.MainVx.Value, cgRes.MainVy.Value, cgRes.MainVz.Value };
  607. double[] adjaSat1 = new double[6] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value, cgRes.Adja1Vx.Value, cgRes.Adja1Vy.Value, cgRes.Adja1Vz.Value };
  608. double[] adjaSat2 = new double[6] { cgRes.Adja2X.Value, cgRes.Adja2Y.Value, cgRes.Adja2Z.Value, cgRes.Adja2Vx.Value, cgRes.Adja2Vy.Value, cgRes.Adja2Vz.Value };
  609. double[] satStation = new double[3] { sRes.SatTxLon, sRes.SatTxLat, 0 };
  610. double[] refStation = new double[3] { sRes.RefLon.Value, sRes.RefLat.Value, 0 };
  611. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  612. var tarDfo1 = cgRes.Dfo1.Value;
  613. var tarDfo2 = cgRes.Dfo2.Value;
  614. var refDfo1 = cgRes.YbMainDfo.Value - cgRes.YbAdja1Dfo.Value;
  615. var refDfo2 = cgRes.YbMainDfo.Value - cgRes.YbAdja2Dfo.Value;
  616. double fu1 = cgRes.TarFreqUp.Value;
  617. double fd1 = cgRes.TarFreqDown.Value;
  618. double fu2 = cgRes.RefFreqUp.Value;
  619. double fd2 = cgRes.RefFreqDown.Value;
  620. double[] res = new double[6];
  621. X3_PosTwoDfo20240305_Core(mainSat, adjaSat1, adjaSat2, satStation, satStation, satStation,
  622. refStation, zone, tarDfo1, tarDfo2, refDfo1, refDfo2, fu1, fd1, fu2, fd2, res);
  623. ConvertToGeoPoint(res);
  624. var posRes = ConvertToGeoPoint(res);
  625. if (CalcConfidence && IsGeoPoint2(posRes))
  626. {
  627. int succeedCount = 0;
  628. for (int i = 0; i < confidenceCount; i++)
  629. {
  630. var mainSatNew = new double[3]
  631. {
  632. cgRes.MainX.Value+RandomHelper.Normal(0,200),
  633. cgRes.MainY.Value+RandomHelper.Normal(0,200),
  634. cgRes.MainZ.Value+RandomHelper.Normal(0,200)
  635. };
  636. var adjaSat1New = new double[3]
  637. {
  638. cgRes.Adja1X.Value+RandomHelper.Normal(0,200),
  639. cgRes.Adja1Y.Value+RandomHelper.Normal(0,200),
  640. cgRes.Adja1Z.Value+RandomHelper.Normal(0,200)
  641. };
  642. var adjaSat2New = new double[3]
  643. {
  644. cgRes.Adja2X.Value+RandomHelper.Normal(0,200),
  645. cgRes.Adja2Y.Value+RandomHelper.Normal(0,200),
  646. cgRes.Adja2Z.Value+RandomHelper.Normal(0,200)
  647. };
  648. var tarDfo1New = (tarDfo1 * 1e6 + RandomHelper.Normal(0, 5)) / 1e6;
  649. var tarDfo2New = (tarDfo2 * 1e6 + RandomHelper.Normal(0, 5)) / 1e6;
  650. var refDfo1New = (refDfo1 * 1e6 + RandomHelper.Normal(0, 5)) / 1e6;
  651. var refDfo2New = (refDfo2 * 1e6 + RandomHelper.Normal(0, 5)) / 1e6;
  652. X3_PosTwoDfo20240305_Core(mainSatNew, adjaSat1New, adjaSat2New, satStation, satStation, satStation, refStation, zone, tarDfo1New, tarDfo2New, refDfo1New, refDfo2New, fu1, fd1, fu2, fd2, res);
  653. var posResNew = ConvertToGeoPoint(res);
  654. if (IsGeoPoint2(posResNew))
  655. {
  656. var distance = PhysicsHelper.DistanceGeo((posRes[0], posRes[1], 0), (posResNew[0], posResNew[1], 0));
  657. if (distance <= confidenceDistance)
  658. {
  659. succeedCount++;
  660. }
  661. }
  662. }
  663. posRes[6] = (int)(succeedCount / (double)confidenceCount * 100);
  664. }
  665. return posRes;
  666. }
  667. /// <summary>
  668. /// 双星时频差带参,返回经度、纬度、高度、镜像点、置信度,数组长度为7
  669. /// </summary>
  670. /// <param name="cgRes">参估结果</param>
  671. /// <param name="sRes">站点信息</param>
  672. /// <param name="CalcConfidence">是否计算置信度</param>
  673. /// <returns></returns>
  674. public static double[] X2_PosDtoDfo(CgRes cgRes, StationRes sRes, bool CalcConfidence = false)
  675. {
  676. if (cgRes.Dto1.Value == 0) return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  677. double[] mainSat = new double[6] { cgRes.MainX.Value, cgRes.MainY.Value, cgRes.MainZ.Value, cgRes.MainVx.Value, cgRes.MainVy.Value, cgRes.MainVz.Value };
  678. double[] adjaSat = new double[6] { cgRes.Adja1X.Value, cgRes.Adja1Y.Value, cgRes.Adja1Z.Value, cgRes.Adja1Vx.Value, cgRes.Adja1Vy.Value, cgRes.Adja1Vz.Value };
  679. double[] satStation = new double[3] { sRes.SatTxLon, sRes.SatTxLat, 0 };
  680. double[] refStation = new double[3] { sRes.RefLon.Value, sRes.RefLat.Value, 0 };
  681. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  682. var tarDto = cgRes.Dto1.Value / 1e6;
  683. var tarDfo = cgRes.Dfo1.Value;
  684. var refDto = (cgRes.YbMainDto.Value - cgRes.YbAdja1Dto.Value) / 1e6;
  685. var refDfo = cgRes.YbMainDfo.Value - cgRes.YbAdja1Dfo.Value;
  686. double fu1 = cgRes.TarFreqUp.Value;
  687. double fd1 = cgRes.TarFreqDown.Value;
  688. double fu2 = cgRes.RefFreqUp.Value;
  689. double fd2 = cgRes.RefFreqDown.Value;
  690. double[] res = new double[6];
  691. X2_Pos20240305_Core(mainSat, adjaSat, satStation, satStation, refStation, zone, tarDto, tarDfo, refDto, refDfo, fu1, fd1, fu2, fd2, res);
  692. ConvertToGeoPoint(res);
  693. var posRes = ConvertToGeoPoint(res);
  694. if (CalcConfidence && IsGeoPoint2(posRes))
  695. {
  696. int succeedCount = 0;
  697. for (int i = 0; i < confidenceCount; i++)
  698. {
  699. var mainSatNew = new double[3]
  700. {
  701. cgRes.MainX.Value+RandomHelper.Normal(0,200),
  702. cgRes.MainY.Value+RandomHelper.Normal(0,200),
  703. cgRes.MainZ.Value+RandomHelper.Normal(0,200)
  704. };
  705. var adjaSatNew = new double[3]
  706. {
  707. cgRes.Adja1X.Value+RandomHelper.Normal(0,200),
  708. cgRes.Adja1Y.Value+RandomHelper.Normal(0,200),
  709. cgRes.Adja1Z.Value+RandomHelper.Normal(0,200)
  710. };
  711. var tarDtoNew = (tarDto * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  712. var refDtoNew = (refDto * 1e6 + RandomHelper.Normal(0, 1)) / 1e6;
  713. var tarDfoNew = (tarDfo * 1e6 + RandomHelper.Normal(0, 5)) / 1e6;
  714. var refDfoNew = (refDfo * 1e6 + RandomHelper.Normal(0, 5)) / 1e6;
  715. X2_Pos20240305_Core(mainSatNew, adjaSatNew, satStation, satStation, refStation, zone, tarDtoNew, tarDfoNew, refDtoNew, refDfoNew, fu1, fd1, fu2, fd2, res);
  716. var posResNew = ConvertToGeoPoint(res);
  717. if (IsGeoPoint2(posResNew))
  718. {
  719. var distance = PhysicsHelper.DistanceGeo((posRes[0], posRes[1], 0), (posResNew[0], posResNew[1], 0));
  720. if (distance <= confidenceDistance)
  721. {
  722. succeedCount++;
  723. }
  724. }
  725. }
  726. posRes[6] = (int)(succeedCount / (double)confidenceCount * 100);
  727. }
  728. return posRes;
  729. }
  730. private static double[] ConvertToGeoPoint(double[] res)
  731. {
  732. if (res == null || res.Length == 0)
  733. {
  734. return new double[7] { 999, 999, 0, 999, 999, 0, -1 };
  735. }
  736. else if (res.Length != 3 && res.Length != 6)
  737. {
  738. throw new Exception("定位结果解析异常,长度不是3或6");
  739. }
  740. var list = res.Select(p => Math.Round(p, 4)).ToArray();
  741. if (list.Length == 3)
  742. {
  743. list = list.Concat(new double[4] { 999, 999, 0, -1 }).ToArray();
  744. }
  745. list[2] = list[5] = 0;//高度
  746. if (double.IsNaN(list[0]) || double.IsNaN(list[1]))
  747. {
  748. list[0] = list[1] = 999;
  749. }
  750. if (double.IsNaN(list[3]) || double.IsNaN(list[4]))
  751. {
  752. list[3] = list[4] = 999;
  753. }
  754. if (list[0] < -180 || list[0] > 180)
  755. {
  756. list[0] = list[1] = 999;
  757. }
  758. else if (list[1] < -90 || list[1] > 90)
  759. {
  760. list[0] = list[1] = 999;
  761. }
  762. if (list[3] < -180 || list[3] > 180)
  763. {
  764. list[3] = list[4] = 999;
  765. }
  766. else if (list[4] < -90 || list[4] > 90)
  767. {
  768. list[3] = list[4] = 999;
  769. }
  770. if (list.Length == 6)
  771. {
  772. var listNew = list.ToList();
  773. listNew.Add(-1);
  774. list = listNew.ToArray();
  775. }
  776. return list;
  777. }
  778. private static bool IsGeoPoint(double[] res)
  779. {
  780. if (res.Length != 3) return false;
  781. if (res[0] < -180 || res[0] > 180)
  782. {
  783. return false;
  784. }
  785. else if (res[1] < -90 || res[1] > 90)
  786. {
  787. return false;
  788. }
  789. return true;
  790. }
  791. private static bool IsGeoPoint2(double[] res)
  792. {
  793. if (res.Length < 3) return false;
  794. if (res[0] < -180 || res[0] > 180)
  795. {
  796. return false;
  797. }
  798. else if (res[1] < -90 || res[1] > 90)
  799. {
  800. return false;
  801. }
  802. return true;
  803. }
  804. }
  805. }