Find the point on a circle with given center point, radius, and degree

后端 未结 10 1858
后悔当初
后悔当初 2020-12-02 06:57

It\'s been 10 years since I did any math like this... I am programming a game in 2D and moving a player around. As I move the player around I am trying to calculate the poin

10条回答
  •  甜味超标
    2020-12-02 07:33

    You should post the code you are using. That would help identify the problem exactly.

    However, since you mentioned measuring your angle in terms of -360 to 360, you are probably using the incorrect units for your math library. Most implementations of trigonometry functions use radians for their input. And if you use degrees instead...your answers will be weirdly wrong.

    x_oncircle = x_origin + 200 * cos (degrees * pi / 180)
    y_oncircle = y_origin + 200 * sin (degrees * pi / 180)
    

    Note that you might also run into circumstance where the quadrant is not what you'd expect. This can fixed by carefully selecting where angle zero is, or by manually checking the quadrant you expect and applying your own signs to the result values.

提交回复
热议问题