User:Necolatis/terrain detection from nasal
Jump to navigation
Jump to 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");
}
}