add functions to calculate other speeds, etc

This commit is contained in:
Sven Czarnian
2021-11-13 22:53:28 +01:00
parent b3c98cdcea
commit bf10649df6

View File

@@ -132,11 +132,10 @@ class WeatherModel:
else: else:
self.LastWeatherUpdate = None self.LastWeatherUpdate = None
def calculateGS(self, altitude : int, ias : int, heading : int): def interpolateWindData(self, altitude : int):
self.updateWindModel() self.updateWindModel()
tas = self.calculateTAS(altitude, ias)
# initialize the wind data # initialized the wind data
if None != self.WindDirectionModel and None != self.WindSpeedModel: if None != self.WindDirectionModel and None != self.WindSpeedModel:
direction = 0.0 direction = 0.0
speed = 0.0 speed = 0.0
@@ -151,5 +150,32 @@ class WeatherModel:
speed = 0 speed = 0
direction = 0 direction = 0
# calculate the ground speed based on the headwind component return speed, direction
def calculateGS(self, altitude : int, ias : int, heading : int):
speed, direction = self.interpolateWindData(altitude)
tas = self.calculateTAS(altitude, ias)
return tas + speed * math.cos(math.radians(direction) - math.radians(heading)) return tas + speed * math.cos(math.radians(direction) - math.radians(heading))
def convertGSToTAS(self, altitude : int, gs : int, heading : int):
speed, direction = self.interpolateWindData(altitude)
return gs - speed * math.cos(math.radians(direction) - math.radians(heading))
def estimateCourse(self, altitude : int, gs : int, heading : int):
tas = self.convertGSToTAS(altitude, gs, heading)
speed, direction = self.interpolateWindData(altitude)
aca = heading - direction
wca = speed * aca / tas
if 0 <= aca:
course = heading + wca
else:
course = heading - wca
while 0 > course:
course += 360
while 360 < course:
course -= 360
return course