Thursday, July 5, 2018

mathematics - Moving an object in a circular path


I want to move one object (dot) in a circular path. How should I change the X and Y coordinates to accomplish this?




Answer



You can do that using simple math:


X := originX + cos(angle)*radius;
Y := originY + sin(angle)*radius;

(originX, originY) is the center of your circle. radius is its radius. That's it.


This works because the sine and cosine are mathematically related to the unit circle.


relationship of sine and cosine to the unit circle
Image credit: LucasVB (Own work) [Public domain], via Wikimedia Commons. (Scaled down to 70%.)


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...