forked from mpusz/mp-units
refactor: examples refactored to benefit from the latest features
This commit is contained in:
@@ -157,18 +157,14 @@ distance spherical_distance(position<T> from, position<T> to)
|
||||
// const auto central_angle = 2 * asin(sqrt(0.5 - cos(lat2_rad - lat1_rad) / 2 + cos(lat1_rad) * cos(lat2_rad) * (1
|
||||
// - cos(lon2_rad - lon1_rad)) / 2));
|
||||
|
||||
// TODO can we improve the below
|
||||
// return quantity_cast<isq::distance>(earth_radius * central_angle);
|
||||
return earth_radius.number() * central_angle * isq::distance[earth_radius.unit];
|
||||
return quantity_cast<isq::distance>(earth_radius * central_angle);
|
||||
} else {
|
||||
// the haversine formula
|
||||
const auto sin_lat = sin((lat2_rad - lat1_rad) / 2);
|
||||
const auto sin_lon = sin((lon2_rad - lon1_rad) / 2);
|
||||
const auto central_angle = 2 * asin(sqrt(sin_lat * sin_lat + cos(lat1_rad) * cos(lat2_rad) * sin_lon * sin_lon));
|
||||
|
||||
// TODO can we improve the below
|
||||
// return quantity_cast<isq::distance>(earth_radius * central_angle);
|
||||
return earth_radius.number() * central_angle * isq::distance[earth_radius.unit];
|
||||
return quantity_cast<isq::distance>(earth_radius * central_angle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace glide_computer {
|
||||
// https://en.wikipedia.org/wiki/Flight_planning#Units_of_measurement
|
||||
inline constexpr struct mean_sea_level : mp_units::absolute_point_origin<mp_units::isq::height> {
|
||||
} mean_sea_level;
|
||||
QUANTITY_SPEC(rate_of_climb_speed, mp_units::isq::height / mp_units::isq::time);
|
||||
QUANTITY_SPEC(rate_of_climb_speed, mp_units::isq::speed, mp_units::isq::height / mp_units::isq::time);
|
||||
|
||||
// length
|
||||
using distance = mp_units::quantity<mp_units::isq::distance[mp_units::si::kilo<mp_units::si::metre>]>;
|
||||
@@ -196,8 +196,7 @@ constexpr height agl(altitude glider_alt, altitude terrain_level) { return glide
|
||||
inline mp_units::quantity<mp_units::isq::length[mp_units::si::kilo<mp_units::si::metre>]> length_3d(distance dist,
|
||||
height h)
|
||||
{
|
||||
// TODO Should we be able to calculate this on quantity of different kinds? What to return?
|
||||
return hypot(quantity_cast<mp_units::isq::length>(dist), quantity_cast<mp_units::isq::length>(h));
|
||||
return hypot(dist, h);
|
||||
}
|
||||
|
||||
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt);
|
||||
|
||||
Reference in New Issue
Block a user