NAVYGROUP

- Improved heading into wind
This commit is contained in:
Frank 2023-09-27 10:53:19 +02:00
parent 7453a6c55d
commit 5d40091947
3 changed files with 50 additions and 13 deletions

View File

@ -644,6 +644,41 @@ function VECTOR:SubVec(Vec)
return self return self
end end
--- Calculate the dot product of this VECTOR with another vector. This function works for DCS#Vec2, DCS#Vec3, VECTOR, COORDINATE objects.
-- @param #VECTOR self
-- @param DCS#Vec3 Vec The other vector. Can also be a DCS#Vec2, DCS#Vec3, COORDINATE or VECTOR object.
-- @return #number Dot product Sum_i(a[i]*b[i]). Note that this is a **scalar** and not a vector any more!
function VECTOR:Dot(Vec)
local dot=self.x*Vec.x
if Vec.z then
dot=dot+self.y*Vec.y+self.z*Vec.z
else
-- Vec is 2D ==> we take its y-component for z.
dot=dot+self.z*Vec.y
end
return dot
end
--- Calculate the rotation or cross product of this VECTOR with another vector. This function works for DCS#Vec2, DCS#Vec3, VECTOR, COORDINATE objects.
-- @param #VECTOR self
-- @param DCS#Vec3 Vec The other vector. Can also be a DCS#Vec2, DCS#Vec3, COORDINATE or VECTOR object.
-- @return #VECTOR The cross product vector.
function VECTOR:Rot(Vec)
-- TODO:
local dot=self.x*Vec.x
if Vec.z then
dot=dot+self.y*Vec.y+self.z*Vec.z
else
-- Vec is 2D ==> we take its y-component for z.
dot=dot+self.z*Vec.y
end
return dot
end
--- Get a clone (deep copy) of this vector. --- Get a clone (deep copy) of this vector.
-- @param #VECTOR self -- @param #VECTOR self
@ -1012,8 +1047,6 @@ function VECTOR:ArrowToAll(Vector)
local vec3Start=self:GetVec3() local vec3Start=self:GetVec3()
trigger.action.arrowToAll(coalition , id, vec3Start, vec3End, color, fillColor , lineType, readOnly, "") trigger.action.arrowToAll(coalition , id, vec3Start, vec3End, color, fillColor , lineType, readOnly, "")
return self return self

View File

@ -90,7 +90,7 @@ NAVYGROUP = {
--- NavyGroup version. --- NavyGroup version.
-- @field #string version -- @field #string version
NAVYGROUP.version="1.0.1" NAVYGROUP.version="1.0.2"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list -- TODO list
@ -586,7 +586,7 @@ end
-- @param #string stoptime Stop time, e.g. "9:00" for nine o'clock. Default 90 minutes after start time. -- @param #string stoptime Stop time, e.g. "9:00" for nine o'clock. Default 90 minutes after start time.
-- @param #number speed Wind speed on deck in knots during turn into wind leg. Default 20 knots. -- @param #number speed Wind speed on deck in knots during turn into wind leg. Default 20 knots.
-- @param #boolean uturn If `true` (or `nil`), carrier wil perform a U-turn and go back to where it came from before resuming its route to the next waypoint. If false, it will go directly to the next waypoint. -- @param #boolean uturn If `true` (or `nil`), carrier wil perform a U-turn and go back to where it came from before resuming its route to the next waypoint. If false, it will go directly to the next waypoint.
-- @param #number offset Offset angle in degrees, e.g. to account for an angled runway. Default 0 deg. -- @param #number offset Offset angle clock-wise in degrees, *e.g.* to account for an angled runway. Default 0 deg. Use around -9.1° for US carriers.
-- @return #NAVYGROUP.IntoWind Turn into window data table. -- @return #NAVYGROUP.IntoWind Turn into window data table.
function NAVYGROUP:AddTurnIntoWind(starttime, stoptime, speed, uturn, offset) function NAVYGROUP:AddTurnIntoWind(starttime, stoptime, speed, uturn, offset)
@ -2050,15 +2050,16 @@ end
--- Get wind direction and speed at current position. --- Get wind direction and speed at current position.
-- @param #NAVYGROUP self -- @param #NAVYGROUP self
-- @param #number Altitude Altitude in meters above main sea level at which the wind is calculated. Default 18 meters.
-- @return #number Direction the wind is blowing **from** in degrees. -- @return #number Direction the wind is blowing **from** in degrees.
-- @return #number Wind speed in m/s. -- @return #number Wind speed in m/s.
function NAVYGROUP:GetWind() function NAVYGROUP:GetWind(Altitude)
-- Current position of the carrier or input. -- Current position of the carrier or input.
local coord=self:GetCoordinate() local coord=self:GetCoordinate()
-- Wind direction and speed. By default at 50 meters ASL. -- Wind direction and speed. By default at 18 meters ASL.
local Wdir, Wspeed=coord:GetWind(50) local Wdir, Wspeed=coord:GetWind(Altitude or 18)
return Wdir, Wspeed return Wdir, Wspeed
end end
@ -2103,7 +2104,7 @@ function NAVYGROUP:GetHeadingIntoWind(Offset, vdeck)
Offset=Offset or 0 Offset=Offset or 0
-- Get direction the wind is blowing from. -- Get direction the wind is blowing from.
local windfrom, vwind=self:GetWind() local windfrom, vwind=self:GetWind(18)
-- Convert wind speed to knots. -- Convert wind speed to knots.
vwind=UTILS.MpsToKnots(vwind) vwind=UTILS.MpsToKnots(vwind)
@ -2111,8 +2112,8 @@ function NAVYGROUP:GetHeadingIntoWind(Offset, vdeck)
-- Wind to in knots. -- Wind to in knots.
local windto=(windfrom+180)%360 local windto=(windfrom+180)%360
-- Offset angle in rad. -- Offset angle in rad. We also define the rotation to be clock-wise, which requires a minus sign.
local alpha=math.rad(Offset) local alpha=math.rad(-Offset)
-- Ships min/max speed. -- Ships min/max speed.
local Vmin=4 local Vmin=4
@ -2130,10 +2131,10 @@ function NAVYGROUP:GetHeadingIntoWind(Offset, vdeck)
-- Speed of ship so it matches the desired speed. -- Speed of ship so it matches the desired speed.
local v local v=0
-- Angle wrt. to wind TO-direction -- Angle wrt. to wind TO-direction
local theta local theta=0
if vdeck>vdeckMax then if vdeck>vdeckMax then
-- Boat cannot go fast enough -- Boat cannot go fast enough
@ -2172,6 +2173,9 @@ function NAVYGROUP:GetHeadingIntoWind(Offset, vdeck)
-- Ship heading so cross wind is min for the given wind. -- Ship heading so cross wind is min for the given wind.
local intowind = (540 + (windto + math.deg(theta) )) % 360 local intowind = (540 + (windto + math.deg(theta) )) % 360
-- Debug info.
self:I(self.lid..string.format("Heading into Wind: vship=%.1f, vwind=%.1f, WindTo=%03d°, Theta=%03d°, Heading=%03d", v, vwind, windto, theta, intowind))
return intowind, v return intowind, v
end end

View File

@ -12664,7 +12664,7 @@ function OPSGROUP:_UpdatePosition()
self.positionLast=self.position or self:GetVec3() self.positionLast=self.position or self:GetVec3()
self.headingLast=self.heading or self:GetHeading() self.headingLast=self.heading or self:GetHeading()
self.orientXLast=self.orientX or self:GetOrientationX() self.orientXLast=self.orientX or self:GetOrientationX()
self.velocityLast=self.velocity or self.group:GetVelocityMPS() self.velocityLast=self.velocity or self.group:GetVelocityMPS()
-- Current state. -- Current state.
self.position=self:GetVec3() self.position=self:GetVec3()