2010-09-08 05:21:46 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
2012-03-09 22:44:36 -04:00
|
|
|
#ifndef AP_MATH_H
|
|
|
|
#define AP_MATH_H
|
|
|
|
|
2010-09-08 05:21:46 -03:00
|
|
|
// Assorted useful math operations for ArduPilot(Mega)
|
|
|
|
|
2012-02-17 19:00:26 -04:00
|
|
|
#include <AP_Common.h>
|
2012-07-04 01:14:58 -03:00
|
|
|
#include <math.h>
|
2011-12-15 22:47:07 -04:00
|
|
|
#include <stdint.h>
|
2012-03-09 22:44:36 -04:00
|
|
|
#include "rotations.h"
|
2010-09-08 05:21:46 -03:00
|
|
|
#include "vector2.h"
|
|
|
|
#include "vector3.h"
|
|
|
|
#include "matrix3.h"
|
2012-03-04 23:31:47 -04:00
|
|
|
#include "quaternion.h"
|
2011-12-14 23:34:58 -04:00
|
|
|
#include "polygon.h"
|
2012-02-17 19:00:26 -04:00
|
|
|
|
|
|
|
// define AP_Param types AP_Vector3f and Ap_Matrix3f
|
|
|
|
AP_PARAMDEFV(Matrix3f, Matrix3f, AP_PARAM_MATRIX3F);
|
|
|
|
AP_PARAMDEFV(Vector3f, Vector3f, AP_PARAM_VECTOR3F);
|
2012-02-23 07:56:40 -04:00
|
|
|
|
|
|
|
// a varient of asin() that always gives a valid answer.
|
2012-08-17 03:20:14 -03:00
|
|
|
float safe_asin(float v);
|
2012-02-23 19:40:56 -04:00
|
|
|
|
|
|
|
// a varient of sqrt() that always gives a valid answer.
|
2012-08-17 03:20:14 -03:00
|
|
|
float safe_sqrt(float v);
|
2012-02-23 20:23:12 -04:00
|
|
|
|
2012-03-11 09:17:05 -03:00
|
|
|
// find a rotation that is the combination of two other
|
|
|
|
// rotations. This is used to allow us to add an overall board
|
|
|
|
// rotation to an existing rotation of a sensor such as the compass
|
2012-08-17 03:20:14 -03:00
|
|
|
enum Rotation rotation_combination(enum Rotation r1, enum Rotation r2, bool *found = NULL);
|
2012-03-11 09:17:05 -03:00
|
|
|
|
2012-07-03 20:19:36 -03:00
|
|
|
// return distance in meters between two locations
|
2012-08-17 03:20:14 -03:00
|
|
|
float get_distance(const struct Location *loc1, const struct Location *loc2);
|
2012-07-10 18:49:05 -03:00
|
|
|
|
|
|
|
// return distance in centimeters between two locations
|
2012-08-17 03:20:14 -03:00
|
|
|
int32_t get_distance_cm(const struct Location *loc1, const struct Location *loc2);
|
2012-07-03 20:19:36 -03:00
|
|
|
|
|
|
|
// return bearing in centi-degrees between two locations
|
2012-08-17 03:20:14 -03:00
|
|
|
int32_t get_bearing_cd(const struct Location *loc1, const struct Location *loc2);
|
2012-07-03 20:19:36 -03:00
|
|
|
|
2012-08-17 03:20:14 -03:00
|
|
|
// see if location is past a line perpendicular to
|
|
|
|
// the line between point1 and point2. If point1 is
|
2012-07-03 20:19:36 -03:00
|
|
|
// our previous waypoint and point2 is our target waypoint
|
|
|
|
// then this function returns true if we have flown past
|
|
|
|
// the target waypoint
|
2012-08-17 03:20:14 -03:00
|
|
|
bool location_passed_point(struct Location & location,
|
|
|
|
struct Location & point1,
|
|
|
|
struct Location & point2);
|
2012-07-03 20:19:36 -03:00
|
|
|
|
2012-08-10 22:56:54 -03:00
|
|
|
// extrapolate latitude/longitude given bearing and distance
|
2012-08-17 03:20:14 -03:00
|
|
|
void location_update(struct Location *loc, float bearing, float distance);
|
2012-08-10 22:56:54 -03:00
|
|
|
|
|
|
|
// extrapolate latitude/longitude given distances north and east
|
2012-08-17 03:20:14 -03:00
|
|
|
void location_offset(struct Location *loc, float ofs_north, float ofs_east);
|
2012-08-10 22:56:54 -03:00
|
|
|
|
2012-07-03 20:19:36 -03:00
|
|
|
#endif // AP_MATH_H
|
|
|
|
|