diff --git a/libraries/AP_Math/vector2.cpp b/libraries/AP_Math/vector2.cpp index 39f720dcc9..dce2b87209 100644 --- a/libraries/AP_Math/vector2.cpp +++ b/libraries/AP_Math/vector2.cpp @@ -140,6 +140,12 @@ float Vector2::angle(const Vector2 &v2) const return acosf(cosv); } +template +float Vector2::angle(void) const +{ + return M_PI_2 + atan2f(-x, y); +} + // find the intersection between two line segments // returns true if they intersect, false if they do not // the point of intersection is returned in the intersection argument @@ -255,6 +261,7 @@ template bool Vector2::operator !=(const Vector2 &v) const; template bool Vector2::is_nan(void) const; template bool Vector2::is_inf(void) const; template float Vector2::angle(const Vector2 &v) const; +template float Vector2::angle(void) const; template bool Vector2::segment_intersection(const Vector2& seg1_start, const Vector2& seg1_end, const Vector2& seg2_start, const Vector2& seg2_end, Vector2& intersection); template bool Vector2::circle_segment_intersection(const Vector2& seg_start, const Vector2& seg_end, const Vector2& circle_center, float radius, Vector2& intersection); diff --git a/libraries/AP_Math/vector2.h b/libraries/AP_Math/vector2.h index 0a3e5a0c19..4fe2932068 100644 --- a/libraries/AP_Math/vector2.h +++ b/libraries/AP_Math/vector2.h @@ -98,6 +98,9 @@ struct Vector2 // returns 0 if the vectors are parallel, and M_PI if they are antiparallel float angle(const Vector2 &v2) const; + // computes the angle of this vector in radians, from -Pi to Pi + float angle(void) const; + // check if any elements are NAN bool is_nan(void) const;