Navigation API
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Navigation API
Hi!
Is it possible to include in this API some parameters to return distance and angle data?
print(" name:" .. waypoints["ICAO"] .. " lon:" .. waypoints["LONGITUDE"] .. " lat:" .. waypoints["LATITUDE"]) waypoints["DISTANCE"]) waypoints["DEGREES"])
Thank You
Marcio
Is it possible to include in this API some parameters to return distance and angle data?
print(" name:" .. waypoints["ICAO"] .. " lon:" .. waypoints["LONGITUDE"] .. " lat:" .. waypoints["LATITUDE"]) waypoints["DISTANCE"]) waypoints["DEGREES"])
Thank You
Marcio
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Navigation API
Hi,
I asked for that a long time ago and it was not possible.
I did the math for that and pointed you to it in your other thread.
Keith
I asked for that a long time ago and it was not possible.
I did the math for that and pointed you to it in your other thread.
Code: Select all
---Distance between two gps coordinates---
lat1=-26.139200
lon1=28.24600
lat2=-33.964802
lon2= 18.601700
R = 6371e3
a1 = math.rad(lat1) -- φ1
a2 = math.rad(lat2) -- φ2
o1 = math.rad(lon1) -- λ1
o2 = math.rad(lon2) -- λ2
ax = math.rad(lat2-lat1) -- Δφ
ay = math.rad(lon2-lon1) -- Δλ
a = (math.sin(ax/2)*math.sin(ax/2)) + math.cos(a1) * math.cos(a2) * (math.sin(ay/2)*math.sin(ay/2))
c = 2 * math.atan(math.sqrt(a)/math.sqrt(1-a))
d = R * c
print("Distance in nm "..d/1852)
print("Distance in meters "..d)
print("Distance in Kilometers "..d/1000)
---Bearing between two coordinates---
y = math.sin(o2-o1) * math.cos(a2);
x = math.cos(a1)*math.sin(a2) - math.sin(a1)*math.cos(a2)*math.cos(o2-o1)
brng = math.atan(y, x)
deg_brng=math.deg(brng)
print("Direction/Bearing "..deg_brng)
Keith
Last edited by Keith Baxter on Sun Dec 12, 2021 7:51 am, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Navigation API
Thank You.
Re: Navigation API
It's still on my to-do list. I'll give it a try tonight, maybe we can get it into 4.1. I have all the scripts practically ready, it just needed to be molded into a function.
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Navigation API
Yes, I've seen the scripts already, but as we already know, I need more knowledge in programming to make tools a little more elaborate. However, I would like to know which math formula to include lat2 and lon2 in the script. Lat1 e and Lon1 know it's from the aircraft. I need to integrate the coordinates "LATITUDE" and "LONGITUDE" in the script. Otherwise, I believe that this difficulty, research and solution, adds a little more knowledge. But despite the instrument's complexity, I've been researching and integrating the functions for over 6 months. It is already quite functional and there is little to integrate the rest of the data on the respective screens. Just now at the end I'm resorting to the help on the forum. My intention is to post it on the instruments when finished
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Navigation API
Hi,
Keith
Code: Select all
robR_36witC="font:arimo_bold.ttf; size:36px; color: white; halign:left; valign:center;"
lat1=0
lon1=0
lat2= 0
lon2= 0
background = canvas_add(0, 0, 600, 600, function()
_rect(0,0,400,512)
_fill("blue")
end)
---What this function is doing is creating a TABLE named <waypoints>
local function data_callback(waypoints)
if waypoints ~= nil then
lat2= waypoints[1]["LATITUDE"]
lon2= waypoints[1]["LONGITUDE"]
---Distance between two gps coordinates---
R = 6371e3
a1 = math.rad(lat1) -- φ1
a2 = math.rad(lat2) -- φ2
o1 = math.rad(lon1) -- λ1
o2 = math.rad(lon2) -- λ2
ax = math.rad(lat2-lat1) -- Δφ
ay = math.rad(lon2-lon1) -- Δλ
a = (math.sin(ax/2)*math.sin(ax/2)) + math.cos(a1) * math.cos(a2) * (math.sin(ay/2)*math.sin(ay/2))
c = 2 * math.atan(math.sqrt(a)/math.sqrt(1-a))
d = R * c
print("Distance in nm "..d/1852)
print("Distance in meters "..d)
print("Distance in Kilometers "..d/1000)
---Bearing between two coordinates---
y = math.sin(o2-o1) * math.cos(a2);
x = math.cos(a1)*math.sin(a2) - math.sin(a1)*math.cos(a2)*math.cos(o2-o1)
brng = math.atan(y, x)
deg_brng=math.deg(brng)
print("Direction/Bearing "..deg_brng)
canvas_draw( background,function()
_rect(0,0,400,512)
_fill("blue")
print(" name:" .. waypoints[1]["ICAO"] .. " lon:" .. waypoints[1]["LONGITUDE"] .. " lat:" .. waypoints[1]["LATITUDE"])
_txt("NAME "..waypoints[1]["ICAO"],robR_36witC,40,100)
_txt("Distance "..tostring(string.format("%.2f",d/1852)).." Nm",robR_36witC,40,150)
_txt("Bearing "..tostring(string.format("%.2f",deg_brng)).." °",robR_36witC,40,200)
end)
end
end
function xpl_dataref_subscribe_trottle(...)
-- Local variables
local args = {...}
local user_callback = args[#args - 1]
local delta_ms = table.remove(args, #args)
local data = nil
-- Replace the user callback with our own
args[#args] = function (...)
data = {...}
end
-- Do the actual subscribe
xpl_dataref_subscribe(table.unpack(args))
-- Start a timer that will fire the callback on requested interval
timer_start(0, delta_ms, function()
if data ~= nil then
user_callback(table.unpack(data))
data = nil
end
end)
end
function new_xpl_data(latitude, longitude)
lat1=latitude
lon1=longitude
print("Latitude: " .. lat1)
print("Longitude: " .. lon1)
nav_get_nearest("WAYPOINT",lat1, lon1, 1, data_callback)
data_callback()
end
xpl_dataref_subscribe_trottle("sim/flightmodel/position/latitude", "DOUBLE",
"sim/flightmodel/position/longitude", "DOUBLE", new_xpl_data, 1000)
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
- Marcnamara2021
- Posts: 83
- Joined: Wed Dec 01, 2021 6:00 am
- Location: Sao Jose dos Campos, SP
Re: Navigation API
Thanks for the direction!!!
Re: Navigation API
I don't think you did because they are not available at the moment, I only have them locally on my PC. You're probably confusing it with something else.
- Keith Baxter
- Posts: 4674
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Navigation API
Ralph,
I think the OP is referring to my script.
Ralph, are you going to use similar formulas to my ones for your extra fields in NAV features?
If I remember correct, these parameters were better computed outside of the database plugin. There was an issue with memory/resources/???? computing these fields and AM hanging. Cannot remember.
@Corjan @Ralph will probably know the reason why these fields were not implemented when I queried. I recall something along the lines of calling the Dbase and to compute the var's creating a strain on resources. My mind may well be playing tricks and I am mumbling on unnecessary these day.
Sometimes one has to empty the voids and forget the past. New possibility's are always discovered.
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: Navigation API
It looks very much the same. There's a setting to choose between Rhumb line or Great Circle track. I thought of having the output in meters, then one can decide to convert it to whatever type.
I'm not sure what you mean with the database. Which information do you mean?
I'm not sure what you mean with the database. Which information do you mean?