2012-07-03 20:19:36 -03:00
|
|
|
/*
|
|
|
|
* location.cpp
|
|
|
|
* Copyright (C) Andrew Tridgell 2011
|
|
|
|
*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2012-08-17 03:20:14 -03:00
|
|
|
* this module deals with calculations involving struct Location
|
2012-07-03 20:19:36 -03:00
|
|
|
*/
|
2012-09-18 15:08:18 -03:00
|
|
|
#include <stdlib.h>
|
2012-07-03 20:19:36 -03:00
|
|
|
#include "AP_Math.h"
|
2016-02-25 08:07:27 -04:00
|
|
|
#include "location.h"
|
2012-07-03 20:19:36 -03:00
|
|
|
|
2017-12-03 17:04:30 -04:00
|
|
|
// return horizontal distance between two positions in cm
|
|
|
|
float get_horizontal_distance_cm(const Vector3f &origin, const Vector3f &destination)
|
|
|
|
{
|
|
|
|
return norm(destination.x-origin.x,destination.y-origin.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return bearing in centi-degrees between two positions
|
|
|
|
float get_bearing_cd(const Vector3f &origin, const Vector3f &destination)
|
|
|
|
{
|
|
|
|
float bearing = atan2f(destination.y-origin.y, destination.x-origin.x) * DEGX100;
|
|
|
|
if (bearing < 0) {
|
|
|
|
bearing += 36000.0f;
|
|
|
|
}
|
|
|
|
return bearing;
|
|
|
|
}
|
|
|
|
|
2016-06-01 18:43:01 -03:00
|
|
|
// return true when lat and lng are within range
|
2016-06-06 17:02:56 -03:00
|
|
|
bool check_lat(float lat)
|
|
|
|
{
|
|
|
|
return fabsf(lat) <= 90;
|
|
|
|
}
|
|
|
|
bool check_lng(float lng)
|
|
|
|
{
|
|
|
|
return fabsf(lng) <= 180;
|
|
|
|
}
|
|
|
|
bool check_lat(int32_t lat)
|
|
|
|
{
|
|
|
|
return labs(lat) <= 90*1e7;
|
|
|
|
}
|
|
|
|
bool check_lng(int32_t lng)
|
|
|
|
{
|
|
|
|
return labs(lng) <= 180*1e7;
|
|
|
|
}
|
2016-06-01 18:43:01 -03:00
|
|
|
bool check_latlng(float lat, float lng)
|
|
|
|
{
|
2016-06-06 17:02:56 -03:00
|
|
|
return check_lat(lat) && check_lng(lng);
|
2016-06-01 18:43:01 -03:00
|
|
|
}
|
|
|
|
bool check_latlng(int32_t lat, int32_t lng)
|
|
|
|
{
|
2016-06-06 17:02:56 -03:00
|
|
|
return check_lat(lat) && check_lng(lng);
|
2016-06-01 18:43:01 -03:00
|
|
|
}
|
2019-04-08 10:51:24 -03:00
|
|
|
|