PosApi.cs 46 KB

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