Normalise orientation between 0 and 360

前端 未结 9 1607
不知归路
不知归路 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:38

    I prefer to avoid loops, conditionals, arbitrary offsets (3600), and Math.____() calls:

    var degrees = -123;
    degrees = (degrees % 360 + 360) % 360;
    // degrees: 237
    

提交回复
热议问题