[BB] Calculate distance withing 2 objects on earth surface, latitude longitude

Started by Santiago, October 08, 2020, 19:20:03

Previous topic - Next topic

Santiago

my simply way to get distance of 2 objects placed by latitude and longitude

i have some problems with ecuations and formulas because blitz3d dosent have to much presition.
but this work very good.



;-----------------------------------------------------------------------
;
; Calculo distancia entre dos puntos terrestres. utilizando una esfera en unidades reales
; by. Santiago Gonzalez
;
;-----------------------------------------------------------------------

Graphics3D 1800 , 1000,0 ,2




Global radio# =  1852.0*60.0*57.29578


Global planeta = CreateSphere(18)
FitMesh planeta,-radio#,-radio#,-radio#,radio*2,radio*2,radio*2,1

EntityFX planeta,4
EntityAlpha planeta,1

If FileType("maps\planeta.jpg") = 1 Then
t_planeta = LoadTexture("maps\planeta.jpg")     ;  Textura planeta sobre esfera
EntityTexture planeta,t_planeta
Else
EntityColor planeta,100,100,200
EndIf



SetFont LoadFont("Terminal",20)



Global cam = CreateCamera()
CameraRange cam,100,radio#*4
MoveEntity cam,0,0,-radio*3

Global light = CreateLight(1)
MoveEntity light,0,radio*2,0

;Lat 1             Long 1         Lat 2      Long 2   dist km   dist MN
;-0.00128102   -0.0821921   0.132677   -0.0854198   14.89977544   8.04523512
;-0.00721392   0.425742   -0.001442   -0.0825546   56.52364685   30.52032767

Lat1#=-0.00128102
Long1#=-0.0821921

Lat2#=0.132677
Long2#=-0.0854198


Lat1#= -0.00721392
Long1#= 0.425742

Lat2#= -0.001442
Long2#= -0.0825546

crear_contacto("barco 1",lat1#,long1#,0)
crear_contacto("barco 2",lat2#,long2#,0)


While Not KeyHit(1)

;MoveEntity cam,0,MouseYSpeed()*10000,0
TurnEntity planeta,0,.001,0

PointEntity cam,planeta
RenderWorld()

calc_distancia#("barco 1","barco 2")



Flip

Wend

End

Function calc_distancia#(origen$,destino$)


For c.contacto = Each contacto

If c\nombre$ = origen$ Then

For c2.contacto = Each contacto

If c2\nombre$  = destino$
dist# = EntityDistance(c\pivot,c2\pivot)


Text 30,100,"lat 1 : " + c\lat
Text 30,120,"Long 1 : " + c\long

Text 30,170,"lat 2 : " + c2\lat
Text 30,190,"Long 2 : " + c2\long


Text 30,230,"dist : " + dist#   + " metros"
Text 30,250,"dist : " + dist#*.001   + " km"

Text 30,300 , "resultado deseado : 56.52364685 km  30.52032767 mn     " ;14.89977544 km   8.04523512 mn"
End If
Next

End If


Next

Return dist#

End Function


Type contacto


Field acquire_ID

Field pivot
Field entidad

Field spd# ; velocidad en nudos
Field hdg# ; rumbo gyrocompas grados
Field lat#
Field long#

Field tail_lat#[10]
Field tail_long#[10]


Field largo#
Field ancho#
Field alto#
Field nombre$

Field radar_x
Field radar_y

Field screen_x
Field screen_y

Field selected
Field visible    ; cuenta s fue visible en la ultima pasada de radar

Field archivo$ ;nombre del archivo ship_ara_pepe.txt

Field hora_archivo
Field time_detected_in_frames
Field last_update ;millisecs()

End Type

Function crear_contacto(nombre$,lat#,long#,rumbo#)

c.contacto = New contacto
c\pivot = CreatePivot(planeta)
c\entidad = CreateSphere(8,c\pivot)

e = 100000
ScaleEntity c\entidad,e,e,e

c\lat# = lat#
c\long# = long#
c\hdg# = rumbo#
c\nombre$ = nombre$

TurnEntity c\pivot,lat#,long#,0

MoveEntity c\pivot,0,0,-radio#

EntityColor c\entidad,Rnd(255),Rnd(255),Rnd(255)

End Function