function PolarProjection3DX takes real FromX, real FromY, real FromZ, real Dist, real Angle, real AngleZ returns real
// Returns the X-coordinate of a 3d polar projection
return FromX + ( FromZ + Dist * Cos(AngleZ * bj_DEGTORAD) ) * Cos(Angle * bj_DEGTORAD)
endfunction
function PolarProjection3DY takes real FromX, real FromY, real FromZ, real Dist, real Angle, real AngleZ returns real
// Returns the Y-coordinate of a 3d polar projection
return FromY + ( FromZ + Dist * Cos(AngleZ * bj_DEGTORAD) ) * Sin(Angle * bj_DEGTORAD)
endfunction
function PolarProjection3DZ takes real FromX, real FromY, real FromZ, real Dist, real Angle, real AngleZ returns real
// Returns the Z-coordinate of a 3d polar projection
// This function does not need all its parameters, but it is easier to handle with all parameters
return FromZ + Dist * Sin(AngleZ * bj_DEGTORAD)
endfunction
function Distance3DBetweenCoordinates takes real FromX, real FromY, real FromZ, real ToX, real ToY, real ToZ returns real
// Returns the 3d-distance between two 3d-coordinates
local real DistX = ToX - FromX
local real DistY = ToY - FromY
local real DistZ = ToZ - FromZ
return SquareRoot( DistX * DistX + DistY * DistY + DistZ * DistZ )
endfunction
function Distance3DBetweenUnits takes unit Unit1, unit Unit2 returns real
// Returns the 3d-distance between two 3d-coordinates
// The distance may be wrong, when a ground-unit is flying over water,
// because GetLocationZ returns the height of water then
// This problem does not match to flying, floating or amphibious units
local location Loc1 = GetUnitLoc( Unit1 )
local location Loc2 = GetUnitLoc( Unit2 )
local real DistX = GetLocationX( Loc2 ) - GetLocationX( Loc1 )
local real DistY = GetLocationY( Loc2 ) - GetLocationY( Loc1 )
local real DistZ = GetLocationZ( Loc2 ) - GetLocationZ( Loc1 ) + GetUnitFlyHeight( Unit2 ) - GetUnitFlyHeight( Unit1 )
call RemoveLocation( Loc1 )
call RemoveLocation( Loc2 )
set Loc1 = null
set Loc2 = null
return SquareRoot( DistX * DistX + DistY * DistY + DistZ * DistZ )
endfunction