Sign in to follow this  
Fire Lancer

Wrapping number to range

Recommended Posts

How can I wrap a number round so it stays within a range? eg keeping a direction number between PI and -PI(radians) or 180 and -180(degrees) I considered using two while loops, to do this at set points, but was wondering if theres a faster way...
double WrapRadians(double Dir)
{
    while(Dir >   M_PI)Dir -= M_PI;
    while(Dir <= -M_PI)Dir += M_PI;
    return Dir;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this