How to calculate position on a circle with a certain angle?

后端 未结 3 1270
生来不讨喜
生来不讨喜 2021-02-19 04:54

I\'m trying to figure out how I could be able to calculate coordinates on a circle. For simplicity I made some images.

3条回答
  •  生来不讨喜
    2021-02-19 05:22

    One elegant way to accomplish this is using complex numbers, available for example here.

    In pseudo-code:

    z = (x_old + I*y_old)*exp(I*angle);
    x_new = real(z);
    y_new = imag(z);
    

    NOTE: the rotation angle needs to be in radians. NOTE2: this assumes a circle centred at (0,0). Just add a shift if the center is not there.

提交回复
热议问题