Normalise orientation between 0 and 360

前端 未结 9 1599
不知归路
不知归路 2021-01-30 10:58

I\'m working on a simple rotate routine which normalizes an objects rotation between 0 and 360 degrees. My C# code seems to be working but I\'m not entirely happy with it. Can a

9条回答
  •  时光说笑
    2021-01-30 11:56

    formula for re-orienting circular values i.e to keep angle between 0 and 359 is:

    angle + Math.ceil( -angle / 360 ) * 360
    

    generalized formula for shifting angle orientation can be:

    angle + Math.ceil( (-angle+shift) / 360 ) * 360
    

    in which value of shift represent circular shift for e.g I want values in -179 to 180 then it can be represented as: angle + Math.ceil( (-angle-179) / 360 ) * 360

提交回复
热议问题