From 4a594f41b0edeace83b328f5b307a49551c8caf9 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 6 Oct 2023 11:30:59 +0200 Subject: [PATCH] #SET_ZONE * Added GetAverageCoordinate() --- Moose Development/Moose/Core/Set.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index bf98911ef..dac994af1 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -6052,7 +6052,29 @@ do -- SET_ZONE return self end - + + --- Get the average aggregated coordinate of this set of zones. + -- @param #SET_ZONE self + -- @return Core.Point#COORDINATE + function SET_ZONE:GetAverageCoordinate() + local x,y,z = 0,0,0 + local count = 0 + for _,_zone in pairs(self.Set) do + local zone=_zone --Core.Zone#ZONE + local vec3 = zone:GetVec3() + x = x + vec3.x + y = y + vec3.y + z = z + vec3.z + count = count + 1 + end + if count > 1 then + x = x/count + y = y/count + z = z/count + end + local coord = COORDINATE:New(x,y,z) + return coord + end --- Private function. -- @param #SET_ZONE self