Convert an angle in degrees, to a vector

北慕城南 提交于 2019-11-29 10:24:40

Just use:

new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians))

Be sure to convert from degrees to radians with this approach too.

This uses the mathematician's convention of starting from [1, 0] and going in the direction towards [0, 1] (that is counter-clockwise with the orientation that mathematicians use for the two axes).

To use instead your convention (starting from [0, -1] and going in the direction of [1, 0]) you need:

new Vector2((float)Math.Sin(radians), -(float)Math.Cos(radians))

Note that your conversion from degrees to radians can never be exact (it involves something with π). You should allow for some tolerance in your tests. Also, if you use double instead of float for the radians, you will have some extra precision in the intermediate calculation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!