Вопрос

I am rather stuck right now. I am trying to develop a game in which an image moves around the circumference of a circle, but I have no idea how to do it. I know radians, Pi and trigonometry are involved, and I know some basic maths involving them, but I cant figure out how to do it. I need the center of an image to move a certain amount on the x-axis per frame (delta-x) and a certain amount on the y-axis(delta-y.) These values will determine the movement per frame that the image must perform to give the impression that it is moving in a circular motion. I don't know how to calculate the delta-x and delta-y values, and seeing as this is a crucial component of my game, it is definitely something which needs to be taken care of. If anybody could help, I would be very grateful.

Это было полезно?

Решение

If you have the coordinates of the center and the radius of the circle it's simply

x = c.x + radius*cos(angle);
y = c.y + radius*sin(angle);

where c is the center and angle goes from 0 to 2*M_PI

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top