User:Necolatis/terrain detection from nasal

From FlightGear wiki
< User:Necolatis
Revision as of 21:52, 4 January 2017 by Necolatis (Talk | contribs) (1st example done. For moderators: please don't delete this page.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is mostly a page for Richard and James to see that many use cases are easily solved in Nasal, with the new wrapper:

Check for terrain between 2 planes

This example is typically for radar use.

var myPos = geo.aircraft_position();
var otherPos = geo.aircraft_position().apply_course_distance(100, 20);# another plane 20 miles out

# Check for terrain between own aircraft and other:
v = get_cart_ground_intersection(myPos.x(), myPos.y(), myPos.z(), otherPos.x()-myPos.x(), otherPos.y()-myPos.y(), otherPos.z()-myPos.z());
if (v == nil) {
 printf("No terrain, planes has clear view of each other");
} else {
 var terrain =;
 var maxDist = myPos.direct_distance_to(otherPos);
 var terrainDist = myPos.direct_distance_to(terrain);
 if (terrainDist < maxDist) {
   print("terrain found between the planes");
 } else {
  print("The planes has clear view of each other");