- geo.elevation: make intersection vector origin's altitude configurable
to allow measuring terrain elevation under solid objects - coding style unification
This commit is contained in:
parent
020e495197
commit
fc9b2dd2a5
1 changed files with 85 additions and 57 deletions
|
@ -1,40 +1,63 @@
|
|||
# geo functions
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
# geo.Coord class
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# geo.Coord.new([<coord>]) ... class that holds and maintains geographical coordinates
|
||||
# can be initialized with another geo.Coord instance
|
||||
# Coord.set(<coord>) ... sets coordinates from another geo.Coord instance
|
||||
#
|
||||
# Coord.set_lat(<num>) ... functions for setting latitude/longitude/altitude
|
||||
# Coord.set_lon(<num>)
|
||||
# Coord.set_alt(<num>)
|
||||
# Coord.set_latlon(<num>, <num> [, <num>]) (altitude is optional; default=0)
|
||||
# SETTER METHODS:
|
||||
#
|
||||
# Coord.set_x(<num>) ... functions for setting cartesian x/y/z coordinates
|
||||
# Coord.set_y(<num>)
|
||||
# Coord.set_z(<num>)
|
||||
# Coord.set_xyz(<num>, <num>, <num>)
|
||||
# .set(<coord>) ... sets coordinates from another geo.Coord instance
|
||||
#
|
||||
# Coord.lat()
|
||||
# Coord.lon() ... functions for getting lat/lon/alt
|
||||
# Coord.alt() ... returns altitude in m
|
||||
# Coord.latlon() ... returns vector [<lat>, <lon>, <alt>]
|
||||
# .set_lat(<num>) ... functions for setting latitude/longitude/altitude
|
||||
# .set_lon(<num>)
|
||||
# .set_alt(<num>)
|
||||
# .set_latlon(<num>, <num> [, <num>]) (altitude is optional; default=0)
|
||||
#
|
||||
# Coord.x() ... functions for reading cartesian coords (in m)
|
||||
# Coord.y()
|
||||
# Coord.z()
|
||||
# Coord.xyz() ... returns vector [<x>, <y>, <z>]
|
||||
# .set_x(<num>) ... functions for setting cartesian x/y/z coordinates
|
||||
# .set_y(<num>)
|
||||
# .set_z(<num>)
|
||||
# .set_xyz(<num>, <num>, <num>)
|
||||
#
|
||||
# Coord.course_to(<coord>) ... returns course to another geo.Coord instance (degree)
|
||||
# Coord.distance_to(<coord>) ... returns distance in m along Earth curvature, ignoring altitudes
|
||||
#
|
||||
# GETTER METHODS:
|
||||
#
|
||||
# .lat()
|
||||
# .lon() ... functions for getting lat/lon/alt
|
||||
# .alt() ... returns altitude in m
|
||||
# .latlon() ... returns vector [<lat>, <lon>, <alt>]
|
||||
#
|
||||
# .x() ... functions for reading cartesian coords (in m)
|
||||
# .y()
|
||||
# .z()
|
||||
# .xyz() ... returns vector [<x>, <y>, <z>]
|
||||
#
|
||||
#
|
||||
# QUERY METHODS:
|
||||
#
|
||||
# .is_defined() ... returns whether the coords are defined
|
||||
# .dump() ... outputs coordinates
|
||||
# .course_to(<coord>) ... returns course to another geo.Coord instance (degree)
|
||||
# .distance_to(<coord>) ... returns distance in m along Earth curvature, ignoring altitudes
|
||||
# useful for map distance
|
||||
# Coord.direct_distance_to(<coord>) ... distance in m direct, considers altitude,
|
||||
# .direct_distance_to(<coord>) ... distance in m direct, considers altitude,
|
||||
# but cuts through Earth surface
|
||||
#
|
||||
# Coord.apply_course_distance(<course>, <distance>) ... guess what
|
||||
# Coord.dump() ... outputs coordinates
|
||||
# Coord.is_defined() ... returns whether the coords are defined
|
||||
#
|
||||
# MANIPULATION METHODS:
|
||||
#
|
||||
# .apply_course_distance(<course>, <distance>) ... guess what
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# geo.aircraft_position() ... returns current aircraft position as geo.Coord
|
||||
# geo.viewer_position() ... returns viewer position as geo.Coord
|
||||
# geo.click_position() ... returns last click coords as geo.Coord or nil before first click
|
||||
#
|
||||
# geo.tile_path(<lat>, <lon>) ... returns tile path string (e.g. "w130n30/w123n37/942056.stg")
|
||||
|
@ -49,11 +72,11 @@
|
|||
# ... same as above, but lat/lon/elev are taken from a Coord object
|
||||
|
||||
|
||||
var EPSILON = 0.0000000000001;
|
||||
var EPSILON = 1e-15;
|
||||
var ERAD = 6378138.12; # Earth radius (m)
|
||||
|
||||
|
||||
var floor = func(v) { v < 0.0 ? -int(-v) - 1 : int(v) }
|
||||
var floor = func(v) v < 0.0 ? -int(-v) - 1 : int(v);
|
||||
|
||||
|
||||
# class that maintains one set of geographical coordinates
|
||||
|
@ -71,7 +94,6 @@ var Coord = {
|
|||
m._z = nil;
|
||||
if (copy != nil)
|
||||
m.set(copy);
|
||||
|
||||
return m;
|
||||
},
|
||||
_cupdate: func {
|
||||
|
@ -157,10 +179,16 @@ var Coord = {
|
|||
return 0;
|
||||
|
||||
var dlon = dest._lon - me._lon;
|
||||
return math.mod(math.atan2(math.sin(dlon) * math.cos(dest._lat),
|
||||
var ret = nil;
|
||||
call(func ret = math.mod(math.atan2(math.sin(dlon) * math.cos(dest._lat),
|
||||
math.cos(me._lat) * math.sin(dest._lat)
|
||||
- math.sin(me._lat) * math.cos(dest._lat)
|
||||
* math.cos(dlon)), 2 * math.pi) * R2D;
|
||||
* math.cos(dlon)), 2 * math.pi) * R2D, nil, var err = []);
|
||||
if (size(err)) {
|
||||
debug.printerror(err);
|
||||
debug.dump(me._lat, me._lon, dlon, dest._lat, dest._lon, "--------------------------");
|
||||
}
|
||||
return ret;
|
||||
},
|
||||
# arc distance on an earth sphere; doesn't consider altitude
|
||||
distance_to: func(dest) {
|
||||
|
@ -188,7 +216,7 @@ var Coord = {
|
|||
},
|
||||
dump: func {
|
||||
if (me._cdirty and me._pdirty)
|
||||
print("Coord.dump(): coord undefined");
|
||||
print("Coord.dump(): coordinates undefined");
|
||||
|
||||
me._cupdate();
|
||||
me._pupdate();
|
||||
|
@ -298,8 +326,8 @@ var _put_model = func(path, lat, lon, elev_m = nil, hdg = 0, pitch = 0, roll = 0
|
|||
}
|
||||
|
||||
|
||||
var elevation = func(lat, lon) {
|
||||
var d = geodinfo(lat, lon);
|
||||
var elevation = func(lat, lon, maxalt = 10000) {
|
||||
var d = geodinfo(lat, lon, maxalt);
|
||||
return d == nil ? nil : d[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue