Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

User:Necolatis/terrain detection from nasal

From FlightGear wiki
< User:Necolatis
Revision as of 20: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 = geo.Coord.new();
 terrain.set_xyz(v[0],v[1],v[2]);
 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");
 }
}