From 5438cd9635c95601cfa6317c6f19e77d7d065fb0 Mon Sep 17 00:00:00 2001 From: cheveguerra Date: Wed, 27 Sep 2023 15:37:27 -0600 Subject: [PATCH] =?UTF-8?q?27/9/23=20-=20Se=20agreg=C3=B3=20la=20funci?= =?UTF-8?q?=C3=B3n=20"FindInZone"=20a=20Subs=20para=20ver=20si=20una=20ubi?= =?UTF-8?q?caci=C3=B3n=20esta=20dentro=20de=20un=20poligono.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pusher.chv.com.b4a => Pusher.b4a | 0 subs.bas | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) rename pusher.chv.com.b4a => Pusher.b4a (100%) diff --git a/pusher.chv.com.b4a b/Pusher.b4a similarity index 100% rename from pusher.chv.com.b4a rename to Pusher.b4a diff --git a/subs.bas b/subs.bas index 71c876f..7071c5d 100644 --- a/subs.bas +++ b/subs.bas @@ -136,4 +136,51 @@ End Sub 'Centra un panel dentro de un elemento superior Sub centraPanel(elemento As Panel, anchoElementoSuperior As Int) 'ignore elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2) +End Sub + +'Geo-Zone Determination (Point in Polygon) +'Use this to determine If a vehicle is within a defined zone made of 5 or more lat/lon coordinates. +'Point 1 Is also Point 5 (first point And last point are same value). +'You can add the points clockwise or counterclockwise. +Sub FindInZone( polx As List, poly As List, x As Double, y As Double) As Boolean 'ignore + ' polx = list of lats for polygon + ' poly = list of lons for polygon + ' y = lon to test + ' x = lat to test + Dim x1, y1, x2, y2, D As Double + Dim i, ni As Int + ni = 0 + x1 = polx.Get(0) + y1 = poly.Get(0) + For i = 0 To polx.Size -1 + If i < polx.Size Then + x2 = polx.Get(i) + y2 = poly.Get(i) + Else + x2 = polx.Get(0) ' checks the last line + y2 = poly.Get(0) + End If + If y >= Min(y1, y2) Then + If y <= Max(y1, y2) Then + If x <= Max(x1, x2) Then + If (x = x1 And y = y1) Or (x = x1 And x = x2) Then ' checks vertices and vertical lines + Return True + End If + If y1 <> y2 Then + D = (y - y1) * (x2 - x1) / (y2 - y1) + x1 + If x1 = x2 Or x <= D Then + ni = ni + 1 + End If + End If + End If + End If + End If + x1 = x2 + y1 = y2 + Next + If ni Mod 2 = 0 Then + Return False + Else + Return True + End If End Sub \ No newline at end of file