Advertisement
WaffleJohns

Celestial Nav Calculator for Scilab

Aug 10th, 2021 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.06 KB | None | 0 0
  1. //hs is hight read off sextant
  2.  
  3. //aries correction sha and dec are values read off a nauitcal almanic such as https://thenauticalalmanac.com/TNARegular/2021_Nautical_Almanac.pdf
  4.  
  5. //aplat and aplong are Assumed Points for lat and long. Basically this is an guess of where you think you are
  6.  
  7. //Basically this is what happens. It finds out where the star is in the sky using the SHA aries correction and DEC. Then it calculates what the sextant reading would have been if you were actually on the assumed point. It compares that answer with the actual sextant reading and adjust accordingly creating a line that you are either on or near. If you do this with two or more stars your position should be on or near the intersection of the two lines. Probably accurate to 50 NM.. This script may not work in the Eastern Hemisphere. I have not checked yet
  8.  
  9.  
  10. //I broke something lol
  11.  
  12. hs1 =
  13. aries1 =
  14. correction1 =
  15. sha1 =
  16. dec1 =
  17. aplat1 =
  18. aplong1 =
  19. star1 = aries1 + correction1 + sha1
  20. LHA1 = star1 + aplong1
  21.  
  22. hs2 =
  23. aries2 =
  24. correction2 =
  25. sha2 =
  26. dec2 =
  27. aplat2 =
  28. aplong2 =
  29. star2 = aries2 + correction2 + sha2
  30. LHA2 = star2 + aplong2
  31.  
  32.  
  33. if LHA1 < 360 then
  34. LHA1 = LHA1 + 360
  35. end
  36. if LHA1 > 360 then
  37. LHA1 = LHA1 - 360
  38. end
  39. if LHA2 < 360 then
  40. LHA2 = LHA2 + 360
  41. end
  42. if LHA2 > 360 then
  43. LHA2 = LHA2 - 360
  44. end
  45.  
  46. if aplat1 > 0 then
  47. aplatL1 = "N"
  48. else
  49. aplatL1 = "S"
  50. end
  51. if aplat2 > 0 then
  52. aplatL2 = "N"
  53. else
  54. aplatL2 = "S"
  55. end
  56.  
  57. //Find the Alt of the star at the AP
  58. if aplat1/abs(aplat1) == dec1/abs(dec1) then
  59. hc1 = asind(cosd(LHA1)*cosd(aplat1)*cosd(dec1) + sind(aplat1)*sind(dec1))
  60. else
  61. hc1 = asind(cosd(LHA1)*cosd(aplat1)*cosd(dec1) - sind(aplat1)*sind(dec1))
  62. end
  63. hd1=hs1-hc1
  64.  
  65. if aplat2/abs(aplat2) == dec2/abs(dec2) then
  66. hc2 = asind(cosd(LHA2)*cosd(aplat2)*cosd(dec2) + sind(aplat2)*sind(dec2))
  67. else
  68. hc2 = asind(cosd(LHA2)*cosd(aplat2)*cosd(dec2) - sind(aplat2)*sind(dec2))
  69. end
  70. hd2=hs2-hc2
  71.  
  72.  
  73. //Find the direction to the star at the AP
  74. a1=abs(tand(aplat1)/tand(LHA1))
  75. if LHA1 > 90 & LHA1 < 270 then
  76. aL1 = aplatL1
  77. elseif aplatL1 == "S" then
  78. aL1 = "N"
  79. elseif aplatL1 == "N" then
  80. aL1 = "S"
  81. end
  82. a2=abs(tand(aplat2)/tand(LHA2))
  83. if LHA2 > 90 & LHA2 < 270 then
  84. aL2 = aplatL2
  85. elseif aplatL2 == "S" then
  86. aL2 = "N"
  87. elseif aplatL2 == "N" then
  88. aL2 = "S"
  89. end
  90.  
  91. b1=abs(tand(dec1)/sind(LHA1))
  92. if dec1 > 0 then
  93. bL1 = "N"
  94. else
  95. bL1 = "S"
  96. end
  97. b2=abs(tand(dec2)/sind(LHA2))
  98. if dec2 > 0 then
  99. bL2 = "N"
  100. else
  101. bL2 = "S"
  102. end
  103.  
  104.  
  105.  
  106. if bL1 == aL1 then
  107. c1=a1+b1
  108. elseif bL1 ~= aL1 then
  109. c1=abs(a1-b1)
  110. end
  111. if a1 > b1 then
  112. cL1 = aL1
  113. elseif a1 < b1
  114. cL1 = bL1
  115. end
  116. if bL2 == aL2 then
  117. c2=a2+b2
  118. elseif bL2 ~= aL2 then
  119. c2=abs(a2-b2)
  120. end
  121. if a2 > b2 then
  122. cL2 = aL2
  123. elseif a2 < b2
  124. cL2 = bL2
  125. end
  126.  
  127.  
  128.  
  129.  
  130. az1=atand(1/c1/cosd(aplat1))
  131. azVL1 = cL1
  132. if LHA1 < 180 then
  133. azHL1 = "W"
  134. elseif LHA1 > 180
  135. azHL1 = "E"
  136. end
  137.  
  138. if azVL1 == "N" & azHL1 == "E" then
  139. azT1 = az1
  140. elseif azVL1 == "S" & azHL1 == "E" then
  141. azT1 = 180 - az1
  142. elseif azVL1 == "S" & azHL1 == "W" then
  143. azT1 = 180 + az1
  144. elseif azVL1 == "N" & azHL1 == "W" then
  145. azT1 = 270 + (90 - az1)
  146. end
  147.  
  148. az2=atand(1/c2/cosd(aplat2))
  149. azVL2 = cL2
  150. if LHA2 < 180 then
  151. azHL2 = "W"
  152. elseif LHA2 > 180
  153. azHL2 = "E"
  154. end
  155. if azVL2 == "N" & azHL2 == "E" then
  156. azT2 = az2
  157. elseif azVL1 == "S" & azHL2 == "E" then
  158. azT2 = 180 - az2
  159. elseif azVL2 == "S" & azHL2 == "W" then
  160. azT2 = 180 + az2
  161. elseif azVL2 == "N" & azHL2 == "W" then
  162. azT2 = 270 + (90 - az2)
  163. end
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. //Drawing corrections
  171. //Caplat = Corrected aplat
  172.  
  173. Caplat1 = aplat1 + hd1*cosd(azT1)
  174. Caplong1 = aplong1 + hd1*sind(azT1)
  175.  
  176.  
  177. Caplat2 = aplat2 + hd2*cosd(azT2)
  178. Caplong2 = aplong2 + hd2*sind(azT2)
  179.  
  180.  
  181. //The Intersection Point
  182. x=Caplong1-Caplong2
  183. y=Caplat1-Caplat2
  184. c=sqrt(x^2+y^2)
  185. theta1=atand(y/x)
  186. theta2=atand(x/y)
  187. phi1=90 - (azT1-90) - (theta1)
  188. phi2= 180 - theta2 - (360-azT2-90)
  189. //phii2 = 90 - (azT2-90) - theta2
  190. angleC = 180 - phi1 - phi2
  191. L1=c*sind(phi1)/sind(angleC)
  192. L2=c*sind(phi2)/sind(angleC)
  193. EPY=L2*sind(90-(azT1-90)) + Caplat1
  194. EPX=L2*cosd(90-(azT1-90)) + Caplong1
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. //Chart Plotting
  202. Appx1 = Caplong1 + (L2+1)*sind(azT1+90)
  203. Appy1 = Caplat1 + (L2+1)*cosd(azT1+90)
  204. Bppx1 = Caplong1 - (L2+1)*sind(azT1+90)
  205. Bppy1 = Caplat1 - (L2+1)*cosd(azT1+90)
  206. xpts1 = [Appx1 Bppx1];
  207. ypts1 = [Appy1 Bppy1];
  208. Clinex1 = [aplong1 Caplong1];
  209. Cliney1 = [aplat1 Caplat1];
  210.  
  211. Appx2 = Caplong2 + (L1+1)*sind(azT2+90)
  212. Appy2 = Caplat2 + (L1+1)*cosd(azT2+90)
  213. Bppx2 = Caplong2 - (L1+1)*sind(azT2+90)
  214. Bppy2 = Caplat2 - (L1+1)*cosd(azT2+90)
  215. xpts2 = [Appx2 Bppx2];
  216. ypts2 = [Appy2 Bppy2];
  217. Clinex2 = [aplong2 Caplong2];
  218. Cliney2 = [aplat2 Caplat2];
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227. //Create a new AP on the EPX and EPY and stuff
  228. aplat3 = EPY
  229. aplong3 = EPX
  230. LHA3 = star1 + aplong3
  231.  
  232. aplat4 = EPY
  233. aplong4 = EPX
  234. LHA4 = star2 + aplong4
  235.  
  236.  
  237.  
  238.  
  239. if LHA3 < 360 then
  240. LHA3 = LHA3 + 360
  241. end
  242. if LHA3 > 360 then
  243. LHA3 = LHA3 - 360
  244. end
  245. if aplat3 > 0 then
  246. aplatL3 = "N"
  247. else
  248. aplatL3 = "S"
  249. end
  250.  
  251. if LHA4 < 360 then
  252. LHA4 = LHA4 + 360
  253. end
  254. if LHA4 > 360 then
  255. LHA4 = LHA4 - 360
  256. end
  257. if aplat4 > 0 then
  258. aplatL4 = "N"
  259. else
  260. aplatL4 = "S"
  261. end
  262.  
  263.  
  264.  
  265.  
  266. if aplat3/abs(aplat3) == dec1/abs(dec1) then
  267. hc3 = asind(cosd(LHA3)*cosd(aplat3)*cosd(dec1) + sind(aplat3)*sind(dec1))
  268. else
  269. hc3 = asind(cosd(LHA3)*cosd(aplat3)*cosd(dec1) - sind(aplat3)*sind(dec1))
  270. end
  271. hd3=hs1-hc3
  272. if aplat4/abs(aplat4) == dec2/abs(dec2) then
  273. hc4 = asind(cosd(LHA4)*cosd(aplat4)*cosd(dec2) + sind(aplat4)*sind(dec2))
  274. else
  275. hc4 = asind(cosd(LHA4)*cosd(aplat4)*cosd(dec2) - sind(aplat4)*sind(dec2))
  276. end
  277. hd4=hs2-hc4
  278.  
  279.  
  280.  
  281. //Gpood
  282. a3=abs(tand(aplat3)/tand(LHA3))
  283. if LHA3 > 90 & LHA3 < 270 then
  284. aL3 = aplatL3
  285. elseif aplatL3 == "S" then
  286. aL3 = "N"
  287. elseif aplatL3 == "N" then
  288. aL3 = "S"
  289. end
  290. a4=abs(tand(aplat4)/tand(LHA4))
  291. if LHA4 > 90 & LHA4 < 270 then
  292. aL4 = aplatL4
  293. elseif aplatL4 == "S" then
  294. aL4 = "N"
  295. elseif aplatL4 == "N" then
  296. aL4 = "S"
  297. end
  298.  
  299.  
  300. //Gpood
  301. b3=abs(tand(dec1)/sind(LHA3))
  302. if dec1 > 0 then
  303. bL3 = "N"
  304. else
  305. bL3 = "S"
  306. end
  307. b4=abs(tand(dec2)/sind(LHA4))
  308. if dec2 > 0 then
  309. bL4 = "N"
  310. else
  311. bL4 = "S"
  312. end
  313.  
  314.  
  315.  
  316. //Gpood
  317.  
  318. if bL3 == aL3 then
  319. c3=a3+b3
  320. elseif bL3 ~= aL3 then
  321. c3=abs(a3-b3)
  322. end
  323. if a3 > b3 then
  324. cL3 = aL3
  325. elseif a3 < b3
  326. cL3 = bL3
  327. end
  328. if bL4 == aL4 then
  329. c4=a4+b4
  330. elseif bL4 ~= aL4 then
  331. c4=abs(a4-b4)
  332. end
  333. if a4 > b4 then
  334. cL4 = aL4
  335. elseif a4 < b4
  336. cL4 = bL4
  337. end
  338.  
  339.  
  340. //Gpood
  341. az3=atand(1/c3/cosd(aplat3))
  342. azVL3 = cL3
  343. if LHA3 < 180 then
  344. azHL3 = "W"
  345. elseif LHA3 > 180
  346. azHL3 = "E"
  347. end
  348. az4=atand(1/c4/cosd(aplat4))
  349. azVL4 = cL4
  350. if LHA4 < 180 then
  351. azHL4 = "W"
  352. elseif LHA4 > 180
  353. azHL4 = "E"
  354. end
  355.  
  356.  
  357.  
  358. if azVL3 == "N" & azHL3 == "E" then
  359. azT3 = az3
  360. elseif azVL3 == "S" & azHL3 == "E" then
  361. azT3 = 180 - az3
  362. elseif azVL3 == "S" & azHL3 == "W" then
  363. azT3 = 180 + az3
  364. elseif azVL3 == "N" & azHL3 == "W" then
  365. azT3 = 270 + (90 - az3)
  366. end
  367. if azVL4 == "N" & azHL4 == "E" then
  368. azT4 = az4
  369. elseif azVL4 == "S" & azHL4 == "E" then
  370. azT4 = 180 - az4
  371. elseif azVL4 == "S" & azHL4 == "W" then
  372. azT4 = 180 + az4
  373. elseif azVL4 == "N" & azHL4 == "W" then
  374. azT4 = 270 + (90 - az4)
  375. end
  376.  
  377.  
  378.  
  379.  
  380. Caplat3 = aplat3 + hd3*cosd(azT3)
  381. Caplong3 = aplong3 + hd3*sind(azT3)
  382.  
  383. Caplat4 = aplat4 + hd4*cosd(azT4)
  384. Caplong4 = aplong4 + hd4*sind(azT4)
  385.  
  386. //The Intersection Point 2222
  387. x3=Caplong3-Caplong4
  388. y3=Caplat3-Caplat4
  389. c3=sqrt(x3^2+y3^2)
  390. theta3=atand(y3/x3)
  391. theta4=atand(x3/y3)
  392. phi3=90 - (azT3-90) - (theta3)
  393. phi4= 180 - theta4 - (360-azT4-90)
  394. //phii4 = 90 - (azT4-90) - theta4
  395. angleC3 = 180 - phi3 - phi4
  396. L3=c3*sind(phi3)/sind(angleC3)
  397. L4=c3*sind(phi4)/sind(angleC3)
  398. EPY3=L4*sind(90-(azT3-90)) + Caplat3
  399. EPX3=L4*cosd(90-(azT3-90)) + Caplong3
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406. //Chart Plotting 222222222
  407. Appx3 = Caplong3 + (L4+3)*sind(azT3+90)
  408. Appy3 = Caplat3 + (L4+3)*cosd(azT3+90)
  409. Bppx3 = Caplong3 - (L4+3)*sind(azT3+90)
  410. Bppy3 = Caplat3 - (L4+3)*cosd(azT3+90)
  411. xpts3 = [Appx3 Bppx3];
  412. ypts3 = [Appy3 Bppy3];
  413. Clinex3 = [aplong3 Caplong3];
  414. Cliney3 = [aplat3 Caplat3];
  415.  
  416. Appx4 = Caplong4 + (L3+3)*sind(azT4+90)
  417. Appy4 = Caplat4 + (L3+3)*cosd(azT4+90)
  418. Bppx4 = Caplong4 - (L3+3)*sind(azT4+90)
  419. Bppy4 = Caplat4 - (L3+3)*cosd(azT4+90)
  420. xpts4 = [Appx4 Bppx4];
  421. ypts4 = [Appy4 Bppy4];
  422. Clinex4 = [aplong4 Caplong4];
  423. Cliney4 = [aplat4 Caplat4];
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436. //Plotting
  437. clf
  438. title('Your Estimated Position: ' + string(EPX3) + " " + string(EPY3))
  439.  
  440.  
  441.  
  442. plot(-sha1,dec1,"*Y")
  443. plot(aplong1,aplat1,"*G")
  444. plot(Caplong1,Caplat1,"*R")
  445. plot(xpts1, ypts1)
  446. plot(Clinex1,Cliney1,"G")
  447.  
  448.  
  449.  
  450. plot(-sha2,dec2,"Y--+")
  451. plot(aplong2,aplat2,"G--+")
  452. plot(Caplong2,Caplat2,"R--+")
  453. plot(xpts2, ypts2)
  454. plot(Clinex2,Cliney2, "G")
  455.  
  456.  
  457.  
  458. plot(EPX,EPY,"B--+")
  459. plot(Caplong1+EPX-5,Caplat1+EPY-5,"*W")
  460. plot(Caplong1+EPX+5,Caplat1+EPY+5,"*W")
  461.  
  462.  
  463.  
  464. plot(Caplong3,Caplat3,"o--R")
  465. plot(Caplong4,Caplat4,"o--R")
  466. plot(Clinex3,Cliney3,"G")
  467. plot(Clinex4,Cliney4,"G")
  468. plot(xpts3, ypts3,"R")
  469. plot(xpts4, ypts4,"R")
  470. plot(EPX3,EPY3,"B--+")
  471.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement