Reputation: 32071
I have an angle defined as such:
accelerationX = acceleration.x * kFilteringFactor + accelerationX * (1.0 - kFilteringFactor);
accelerationY = acceleration.y * kFilteringFactor + accelerationY * (1.0 - kFilteringFactor);
double angle = atan2(accelerationY, -accelerationX) + M_PI/2;
I want to limit the value of angle to minimum -pi/3 and max pi/3. So if the value goes over pi/3, it should just stay at pi/3. How can I do this?
Upvotes: 0
Views: 131
Reputation: 14824
if (angle < M_PI/-3)
{
angle = M_PI/-3;
}
else if (angle > M_PI/3)
{
angle = M_PI/3;
}
Upvotes: 1
Reputation: 32893
You can add:
angle = (angle < -M_PI/3 ? -M_PI/3 : (angle > M_PI/3 ? M_PI/3 : angle));
Upvotes: 1