0
votes

Cannot remember the math to use from school however I want to rotate a point around an origin using Go/Golang.

Very basic idea below, x,y is the origin (center) and x2,y2 is the point on the circumference of the circle that moves. I want x2,y2 to rotate 360 around x,y continously.

x:= 10 // center x
y:= 10 // center y

x2 := 20 // rotating point x
y2 := 20 // rotating point y

xchange := ??? What math to use to calculate the change in x
ychange := ??? What math to use to calculate the change in y

Any help would be appreciated.

1

1 Answers

1
votes

You can parametrize a circular orbit around the point (x0, y0) with radius r as

x(t) = x0 + r cos(t)
y(t) = y0 + r sin(t)

You can work out r based on the two points you begin with. From there it’s just a matter of smoothly increasing t to simulate the progress of time.