我有一个如此定义的角度:
accelerationX = acceleration.x * kFilteringFactor + accelerationX * (1.0 - kFilteringFactor);
accelerationY = acceleration.y * kFilteringFactor + accelerationY * (1.0 - kFilteringFactor);
double angle = atan2(accelerationY, -accelerationX) + M_PI/2;
我想将角度值限制为最小值-pi / 3和max pi / 3。因此,如果值超过pi / 3,它应该保持在pi / 3。我怎么能这样做?
答案 0 :(得分:1)
您可以添加:
angle = (angle < -M_PI/3 ? -M_PI/3 : (angle > M_PI/3 ? M_PI/3 : angle));
答案 1 :(得分:1)
if (angle < M_PI/-3)
{
angle = M_PI/-3;
}
else if (angle > M_PI/3)
{
angle = M_PI/3;
}