September 27, 2021, 10:37:24

Author Topic: [BB] Calculate distance withing 2 objects on earth surface, latitude longitude  (Read 1775 times)

Santiago

• Sr. Member
• Posts: 290
• Blitz3d
[BB] Calculate distance withing 2 objects on earth surface, latitude longitude
« on: October 08, 2020, 19:20:03 »
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.

Code: [Select]
`;-----------------------------------------------------------------------; ; Calculo distancia entre dos puntos terrestres. utilizando una esfera en unidades reales; by. Santiago Gonzalez;;-----------------------------------------------------------------------Graphics3D 1800 , 1000,0 ,2Global radio# =  1852.0*60.0*57.29578Global planeta = CreateSphere(18)FitMesh planeta,-radio#,-radio#,-radio#,radio*2,radio*2,radio*2,1EntityFX planeta,4EntityAlpha planeta,1If FileType("maps\planeta.jpg") = 1 Then t_planeta = LoadTexture("maps\planeta.jpg")     ;  Textura planeta sobre esfera EntityTexture planeta,t_planetaElse EntityColor planeta,100,100,200EndIfSetFont LoadFont("Terminal",20)Global cam = CreateCamera()CameraRange cam,100,radio#*4MoveEntity cam,0,0,-radio*3Global 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.52032767Lat1#=-0.00128102Long1#=-0.0821921Lat2#=0.132677Long2#=-0.0854198Lat1#= -0.00721392Long1#= 0.425742Lat2#= -0.001442Long2#= -0.0825546crear_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 WendEndFunction 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 FunctionType 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 TypeFunction 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`