Skip to content
Snippets Groups Projects
Commit 8b87849a authored by Randy Mackay's avatar Randy Mackay
Browse files

Math: add wrap_PI

parent 23ce35d2
No related branches found
No related tags found
No related merge requests found
...@@ -94,6 +94,11 @@ void location_offset(struct Location *loc, float ofs_north, float ofs_eas ...@@ -94,6 +94,11 @@ void location_offset(struct Location *loc, float ofs_north, float ofs_eas
int32_t wrap_360_cd(int32_t error); int32_t wrap_360_cd(int32_t error);
int32_t wrap_180_cd(int32_t error); int32_t wrap_180_cd(int32_t error);
/*
wrap an angle defined in radians to -PI ~ PI (equivalent to +- 180 degrees)
*/
float wrap_PI(float angle_in_radians);
/* /*
print a int32_t lat/long in decimal degrees print a int32_t lat/long in decimal degrees
*/ */
......
...@@ -161,6 +161,15 @@ int32_t wrap_180_cd(int32_t error) ...@@ -161,6 +161,15 @@ int32_t wrap_180_cd(int32_t error)
return error; return error;
} }
/*
wrap an angle defined in radians to -PI ~ PI (equivalent to +- 180 degrees)
*/
float wrap_PI(float angle_in_radians)
{
while (angle_in_radians > PI) angle_in_radians -= 2.0f*PI;
while (angle_in_radians < -PI) angle_in_radians += 2.0f*PI;
return angle_in_radians;
}
/* /*
print a int32_t lat/long in decimal degrees print a int32_t lat/long in decimal degrees
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment