diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 1abf8266f..a45522f2c 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -420,6 +420,57 @@ do -- COORDINATE local SourceVec3 = self:GetVec3() return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5 end + + --- Returns the temperature in Degrees Celsius. + -- @param #COORDINATE self + -- @param height (Optional) parameter specifying the height ASL. + -- @return Temperature in Degrees Celsius. + function COORDINATE:GetTemperature(height) + local y=height or self.y + env.info("FF height = "..y) + local point={x=self.x, y=height or self.y, z=self.z} + -- get temperature [K] and pressure [Pa] at point + local T,P=atmosphere.getTemperatureAndPressure(point) + -- Return Temperature in Deg C + return T-273.15 + end + + --- Returns the pressure in hPa. + -- @param #COORDINATE self + -- @param height (Optional) parameter specifying the height ASL. E.g. set height=0 for QNH. + -- @return Pressure in hPa. + function COORDINATE:GetPressure(height) + local point={x=self.x, y=height or self.y, z=self.z} + -- get temperature [K] and pressure [Pa] at point + local T,P=atmosphere.getTemperatureAndPressure(point) + -- Return Pressure in hPa. + return P/100 + end + + --- Returns the wind direction (from) and strength. + -- @param #COORDINATE self + -- @param height (Optional) parameter specifying the height ASL. The minimum height will be always be the land height since the wind is zero below the ground. + -- @return Direction the wind is blowing from in degrees. + -- @return Wind strength in m/s. + function COORDINATE:GetWind(height) + local landheight=self:GetLandHeight()+0.1 -- we at 0.1 meters to be sure to be above ground since wind is zero below ground level. + local point={x=self.x, y=math.max(height or self.y, landheight), z=self.z} + -- get wind velocity vector + local wind = atmosphere.getWind(point) + local direction = math.deg(math.atan2(wind.z, wind.x)) + if direction < 0 then + direction = 360 + direction + end + -- Convert to direction to from direction + if direction > 180 then + direction = direction-180 + else + direction = direction+180 + end + local strength=math.sqrt((wind.x)^2+(wind.z)^2) + -- Return wind direction and strength km/h. + return direction, strength + end --- Return the 3D distance in meters between the target COORDINATE and the COORDINATE. diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index cd54b4e1f..ef3e836fb 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -432,3 +432,50 @@ function UTILS.IsInSphere( InVec3, Vec3, Radius ) return InSphere end + +-- Beaufort scale: returns Beaufort number and wind description as a function of wind speed in m/s. +function UTILS.BeaufortScale(speed) + local bn=nil + local bd=nil + if speed<0.51 then + bn=0 + bd="Calm" + elseif speed<2.06 then + bn=1 + bd="Light Air" + elseif speed<3.60 then + bn=2 + bd="Light Breeze" + elseif speed<5.66 then + bn=3 + bd="Gentle Breeze" + elseif speed<8.23 then + bn=4 + bd="Moderate Breeze" + elseif speed<11.32 then + bn=5 + bd="Fresh Breeze" + elseif speed<14.40 then + bn=6 + bd="Strong Breeze" + elseif speed<17.49 then + bn=7 + bd="Moderate Gale" + elseif speed<21.09 then + bn=8 + bd="Fresh Gale" + elseif speed<24.69 then + bn=9 + bd="Strong Gale" + elseif speed<28.81 then + bn=10 + bd="Storm" + elseif speed<32.92 then + bn=11 + bd="Violent Storm" + else + bn=12 + bd="Hurricane" + end + return bn,bd +end \ No newline at end of file