mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
OPS
This commit is contained in:
parent
3b2cbea1c4
commit
f4a3f6d433
@ -5772,6 +5772,19 @@ function OPSGROUP:onafterUnloading(From, Event, To)
|
||||
|
||||
-- Create a zone around the carrier.
|
||||
local zoneCarrier=ZONE_RADIUS:New("Carrier", self:GetVec2(), 100)
|
||||
|
||||
|
||||
local d={}
|
||||
d.p1={x=vec2.x-l/2, y=vec2.y-w/2} --DCS#Vec2
|
||||
d.p2={x=vec2.x-l/2, y=vec2.y+w/2} --DCS#Vec2
|
||||
d.p3={x=d2.x+20, y=d2.y+20}
|
||||
d.p4={x=d1.x+20, y=d1.y+20}
|
||||
|
||||
for _,_p in pairs(d) do
|
||||
local p=_p --#DCSVec2
|
||||
end
|
||||
|
||||
local zoneCarrier=ZONE_POLYGON_BASE:New("Carrier", {d1, d2, d3, d4})
|
||||
|
||||
-- Random coordinate/heading in the zone.
|
||||
Coordinate=zoneCarrier:GetRandomCoordinate(50)
|
||||
@ -7978,6 +7991,48 @@ function OPSGROUP:GetElementByName(unitname)
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get the bounding box of the element.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #string UnitName Name of unit.
|
||||
-- @return Core.Zone#ZONE_POLYGON Bounding box polygon zone.
|
||||
function OPSGROUP:GetElementBoundingBox(UnitName)
|
||||
|
||||
local element=self:GetElementByName(UnitName)
|
||||
|
||||
if element and element.status~=OPSGROUP.ElementStatus.DEAD then
|
||||
|
||||
local l=element.length
|
||||
local w=element.width
|
||||
|
||||
local heading=element.unit:GetHeading()
|
||||
|
||||
env.info(string.format("FF l=%d w=%d h=%d", l, w, heading))
|
||||
|
||||
local vec2=self:GetVec2(element.name)
|
||||
|
||||
-- Set of
|
||||
local b={}
|
||||
b[1]={y=l/2, x=-w/2} --DCS#Vec2
|
||||
b[2]={y=l/2, x=w/2} --DCS#Vec2
|
||||
b[3]={y=-l/2, x=w/2} --DCS#Vec2
|
||||
b[4]={y=-l/2, x=-w/2} --DCS#Vec2
|
||||
|
||||
for i,p in pairs(b) do
|
||||
b[i]=UTILS.Vec2Rotate2D(p, heading)
|
||||
end
|
||||
|
||||
local d=UTILS.Vec2Norm(vec2)
|
||||
local h=UTILS.Vec2Hdg(vec2)
|
||||
for i,p in pairs(b) do
|
||||
--b[i]=UTILS.Vec2Translate(p, d, h)
|
||||
end
|
||||
|
||||
return ZONE_POLYGON_BASE:New(element.name, b)
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Get the first element of a group, which is alive.
|
||||
-- @param #OPSGROUP self
|
||||
-- @return #OPSGROUP.Element The element or `#nil` if no element is alive any more.
|
||||
@ -7995,6 +8050,7 @@ function OPSGROUP:GetElementAlive()
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
--- Get number of elements alive.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #string status (Optional) Only count number, which are in a special status.
|
||||
|
||||
@ -931,6 +931,15 @@ function UTILS.VecDot(a, b)
|
||||
return a.x*b.x + a.y*b.y + a.z*b.z
|
||||
end
|
||||
|
||||
--- Calculate the [dot product](https://en.wikipedia.org/wiki/Dot_product) of two 2D vectors. The result is a number.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param DCS#Vec2 b Vector in 2D with x, y components.
|
||||
-- @return #number Scalar product of the two vectors a*b.
|
||||
function UTILS.Vec2Dot(a, b)
|
||||
return a.x*b.x + a.y*b.y
|
||||
end
|
||||
|
||||
|
||||
--- Calculate the [euclidean norm](https://en.wikipedia.org/wiki/Euclidean_distance) (length) of a 3D vector.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @return #number Norm of the vector.
|
||||
@ -938,6 +947,13 @@ function UTILS.VecNorm(a)
|
||||
return math.sqrt(UTILS.VecDot(a, a))
|
||||
end
|
||||
|
||||
--- Calculate the [euclidean norm](https://en.wikipedia.org/wiki/Euclidean_distance) (length) of a 2D vector.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @return #number Norm of the vector.
|
||||
function UTILS.Vec2Norm(a)
|
||||
return math.sqrt(UTILS.Vec2Dot(a, a))
|
||||
end
|
||||
|
||||
--- Calculate the distance between two 2D vectors.
|
||||
-- @param DCS#Vec2 a Vector in 3D with x, y components.
|
||||
-- @param DCS#Vec2 b Vector in 3D with x, y components.
|
||||
@ -1020,6 +1036,17 @@ function UTILS.VecHdg(a)
|
||||
return h
|
||||
end
|
||||
|
||||
--- Calculate "heading" of a 2D vector in the X-Y plane.
|
||||
-- @param DCS#Vec2 a Vector in "D with x, y components.
|
||||
-- @return #number Heading in degrees in [0,360).
|
||||
function UTILS.Vec2Hdg(a)
|
||||
local h=math.deg(math.atan2(a.y, a.x))
|
||||
if h<0 then
|
||||
h=h+360
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
--- Calculate the difference between two "heading", i.e. angles in [0,360) deg.
|
||||
-- @param #number h1 Heading one.
|
||||
-- @param #number h2 Heading two.
|
||||
@ -1056,6 +1083,22 @@ function UTILS.VecTranslate(a, distance, angle)
|
||||
return {x=TX, y=a.y, z=TY}
|
||||
end
|
||||
|
||||
--- Translate 2D vector in the 2D (x,z) plane.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param #number distance The distance to translate.
|
||||
-- @param #number angle Rotation angle in degrees.
|
||||
-- @return DCS#Vec2 Translated vector.
|
||||
function UTILS.Vec2Translate(a, distance, angle)
|
||||
|
||||
local SX = a.x
|
||||
local SY = a.y
|
||||
local Radians=math.rad(angle or 0)
|
||||
local TX=distance*math.cos(Radians)+SX
|
||||
local TY=distance*math.sin(Radians)+SY
|
||||
|
||||
return {x=TX, y=TY}
|
||||
end
|
||||
|
||||
--- Rotate 3D vector in the 2D (x,z) plane. y-component (usually altitude) unchanged.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param #number angle Rotation angle in degrees.
|
||||
@ -1076,6 +1119,25 @@ function UTILS.Rotate2D(a, angle)
|
||||
return A
|
||||
end
|
||||
|
||||
--- Rotate 2D vector in the 2D (x,z) plane.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param #number angle Rotation angle in degrees.
|
||||
-- @return DCS#Vec2 Vector rotated in the (x,y) plane.
|
||||
function UTILS.Vec2Rotate2D(a, angle)
|
||||
|
||||
local phi=math.rad(angle)
|
||||
|
||||
local x=a.y
|
||||
local y=a.x
|
||||
|
||||
local Z=x*math.cos(phi)-y*math.sin(phi)
|
||||
local X=x*math.sin(phi)+y*math.cos(phi)
|
||||
|
||||
local A={x=X, y=Z}
|
||||
|
||||
return A
|
||||
end
|
||||
|
||||
|
||||
--- Converts a TACAN Channel/Mode couple into a frequency in Hz.
|
||||
-- @param #number TACANChannel The TACAN channel, i.e. the 10 in "10X".
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user