Skip to content

Commit

Permalink
Small optimizations. Added code comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
alinnman committed May 15, 2024
1 parent ed76a2f commit 04180e9
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions starfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def getRadius (self):

class starFixPair:
def __init__ (self, sf1, sf2):
assert (type (sf1) == type (sf2) == starFix)
self.sf1 = sf1
self.sf2 = sf2

Expand Down Expand Up @@ -237,53 +238,65 @@ def __init__ (self, sfList):
self.sfList = sfList

def getIntersections (self, limit=100):
if (len(self.sfList) == 2):
nrOfFixes = len(self.sfList)
if (nrOfFixes == 2):
'''
For two star fixes just use the algorithm of starFixPair.getIntersections
'''
intersections = starFixPair (self.sfList[0],self.sfList[1]).getIntersections()
return intersections
else:
elif (nrOfFixes >= 3):
'''
For >= 3 star fixes perform a sorting algorithm
For >= 3 star fixes perform pairwise calculation on every pair of fixes and then run a sorting algorithm
'''
nrOfFixes = len (self.sfList)
coords = []
# Perform pairwise sight reductions
for i in range (nrOfFixes):
for j in range (i+1, nrOfFixes):
p = starFixPair (self.sfList [i], self.sfList [j])
pInt = p.getIntersections ()
if (pInt != None):
if pInt != None:
coords.append (pInt[0])
coords.append (pInt[1])
nrOfCoords = len (coords)
dists = dict ()
# Collect all distance values between intersections
for i in range (nrOfCoords):
for j in range (i, nrOfCoords):
if i != j:
dist = distanceBetweenPoints (coords[i], coords[j])
dists [i,j] = dist
# Sort the distances, with lower distances first
sortedDists = dict(sorted(dists.items(), key=lambda item: item[1]))
nrOfSortedDists = len (sortedDists)
chosenPoints = set ()
cpLimit = int((nrOfFixes**2 - nrOfFixes) / 2)
# Find the points which are located close to other points
for sd in sortedDists:
theDistance = sortedDists [sd]
if (theDistance < limit):
if theDistance < limit:
chosenPoints.add (sd[0])
chosenPoints.add (sd[1])
else:
break
if len (chosenPoints) > cpLimit:
break

nrOfChosenPoints = len (chosenPoints)
if nrOfChosenPoints == 0:
# No points found. Bad star fixes. Return nothing.
return None
summationVec = [0,0,0]
# Make a mean value on the best intersections.
for cp in chosenPoints:
selectedCoord = coords [cp]
rectVec = toRectangular (selectedCoord[0], selectedCoord[1])
summationVec = addVecs (summationVec, multScalarVect (1/nrOfChosenPoints, rectVec))
summationVec = normalizeVect (summationVec)
retLON, retLAT = toLonLat (summationVec)
return retLON, retLAT
else:
return None



0 comments on commit 04180e9

Please sign in to comment.