Differenze tra le versioni di "Calcolare il rilevamento (bearing) in gradi"

Da Gambas-it.org - Wikipedia.
Riga 10: Riga 10:
  
 
Nell'esempio, che segue, si otterrà il ''bearing'' assoluto fra un punto iniziale e un secondo punto (finale), cliccando con il mouse sulla ''MapView'' su due punti differenti.
 
Nell'esempio, che segue, si otterrà il ''bearing'' assoluto fra un punto iniziale e un secondo punto (finale), cliccando con il mouse sulla ''MapView'' su due punti differenti.
 +
Private mmpp As New MapPoint[]
 +
 +
 +
'''Public''' Sub Form_Open()
 +
 
 +
  Dim mp As New MapPoint
 +
   
 +
  With MapView1
 +
    .X = 0
 +
    .Y = 0
 +
    .W = Me.W
 +
    .H = Me.H
 +
    .Map.AddTile("GoogleMap", "https://khms{s}.google.it/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile", ["version": "860"]).SubDomains = ["0", "1", "2"]
 +
    .Map.Zoom = 13
 +
    .Map["GoogleMap"].Visible = True
 +
  End With
 +
 
 +
<FONT Color=gray>' ''Imposta il centro della mappa:''</font>
 +
  mp.Lat = 41.8903
 +
  mp.Lon = 14.492255
 +
  MapView1.Map.Center = mp
 +
 
 +
'''End'''
 +
 +
 +
'''Public''' Sub MapView1_MouseUp()
 +
 
 +
  Dim pt As New Point(Mouse.X, Mouse.Y)
 +
 
 +
  Print " Latitudine "; MapView1.Map.PixelToMapPointRel(pt).Lat; ", "; MapView1.Map.PixelToMapPointRel(pt).Lon
 +
 
 +
  mmpp.Push(MapView1.Map.PixelToMapPointRel(pt))
 +
 
 +
  If mmpp.Count = 2 Then
 +
  Print "Rilevamento "; Fix(MapPoint.Bearing(mmpp[0], mmpp[1])); "*\n\n"
 +
    mmpp.Clear
 +
    mmpp = New MapPoint[]
 +
  Endif
 +
 
 +
'''End'''
 +
 +
 +
 +
oppure più direttamente così:
 
  '''Public''' Sub Form_Open()
 
  '''Public''' Sub Form_Open()
 
    
 
    
Riga 37: Riga 81:
 
   Dim f As Float
 
   Dim f As Float
 
    
 
    
   Print " Latitudine "; CStr(MapView1.Map.PixelToMapPointRel(pt).Lat); ", "; CStr(MapView1.Map.PixelToMapPointRel(pt).Lon)
+
   Print " Latitudine "; MapView1.Map.PixelToMapPointRel(pt).Lat; ", "; MapView1.Map.PixelToMapPointRel(pt).Lon
 
    
 
    
 
   br.Push(Rad(MapView1.Map.PixelToMapPointRel(pt).Lat))
 
   br.Push(Rad(MapView1.Map.PixelToMapPointRel(pt).Lat))

Versione delle 18:42, 18 gen 2020

Il bearing è l'angolo orizzontale (angolo azimutale) tra la direzione di un oggetto e un altro oggetto (bearing relativo), o tra esso e quello del nord vero (bearing assoluto).
Più in particolare il rilevamento relativo si riferisce all'angolo tra la direzione in avanti di un oggetto e la posizione di un altro oggetto considerato. Mentre il rilevamento assoluto si riferisce all'angolo rispetto al punto dell'osservatore tra il nord magnetico (rilevamento magnetico) o il nord reale (rilevamento reale) e un oggetto.

  ogg
 |   /
 |  /
 |^/
 |/
oss.

Nell'esempio, che segue, si otterrà il bearing assoluto fra un punto iniziale e un secondo punto (finale), cliccando con il mouse sulla MapView su due punti differenti.

Private mmpp As New MapPoint[]


Public Sub Form_Open()
 
 Dim mp As New MapPoint
   
 With MapView1
   .X = 0
   .Y = 0
   .W = Me.W
   .H = Me.H
   .Map.AddTile("GoogleMap", "https://khms{s}.google.it/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile", ["version": "860"]).SubDomains = ["0", "1", "2"]
   .Map.Zoom = 13
   .Map["GoogleMap"].Visible = True
 End With
 
' Imposta il centro della mappa:
 mp.Lat = 41.8903
 mp.Lon = 14.492255
 MapView1.Map.Center = mp
  
End


Public Sub MapView1_MouseUp()
 
 Dim pt As New Point(Mouse.X, Mouse.Y)
 
 Print " Latitudine "; MapView1.Map.PixelToMapPointRel(pt).Lat; ", "; MapView1.Map.PixelToMapPointRel(pt).Lon
 
 mmpp.Push(MapView1.Map.PixelToMapPointRel(pt))
 
 If mmpp.Count = 2 Then
 Print "Rilevamento "; Fix(MapPoint.Bearing(mmpp[0], mmpp[1])); "*\n\n"
   mmpp.Clear
   mmpp = New MapPoint[]
 Endif
 
End


oppure più direttamente così:

Public Sub Form_Open()
 
 Dim mp As New MapPoint
   
 With MapView1
   .X = 0
   .Y = 0
   .W = Me.W
   .H = Me.H
   .Map.AddTile("GoogleMap", "https://khms{s}.google.it/kh/v={version}&src=app&x={x}&y={y}&z={z}&s=Galile", ["version": "860"]).SubDomains = ["0", "1", "2"]
   .Map.Zoom = 13
   .Map["GoogleMap"].Visible = True
 End With
 
' Imposta il centro della mappa:
  mp.Lat = 41.8902142
  mp.Lon = 12.4900422
  MapView1.Map.Center = mp
  
End


Public Sub MapView1_MouseUp()
 
 Dim pt As New Point(Mouse.X, Mouse.Y)
 Dim f As Float
 
 Print " Latitudine "; MapView1.Map.PixelToMapPointRel(pt).Lat; ", "; MapView1.Map.PixelToMapPointRel(pt).Lon
 
 br.Push(Rad(MapView1.Map.PixelToMapPointRel(pt).Lat))
 br.Push(Rad(MapView1.Map.PixelToMapPointRel(pt).Lon))
 
 If br.Count = 4 Then
' Si applica la seguente formula: θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
' Dove: φ1,λ1 è il punto iniziale; φ2,λ2 è il punto finale (Δλ è la differenza in longitudine)
   f = ATan2(Sin(br[3] - br[1]) * Cos(br[2]), Cos(br[0]) * Sin(br[2]) - Sin(br[0]) * Cos(br[2]) * Cos(br[3] - br[1]))
   Print "Bearing:    "; (CInt(Deg(f)) + 360) Mod 360; "°\n\n"
   br.Clear
   br = New Float[]
 Endif
  
End