Home > Back-end >  moving in a circular motion from one point to another
moving in a circular motion from one point to another

Time:08-15

2 points on a 2d grid and I need to move my player in a way that would be a circular motion to the other point gradually what would the equation look like on that? like moving from point p to point Q would it relate to the differences in the angles and distance? I'm stumped I feel dumb please help! https://i.stack.imgur.com/N1ykX.png

CodePudding user response:

Circle center

C = (P   Q) / 2

Initial radius-vector (from C to P)

A = (P - Q) / 2

Perpendicular vector

B.x, By = -A.y, A.x

Now SLERP for Ω = Pi/2 in range t = 0..2

R.x = C.x   sin((1-t)*Pi/2)*A.x - sin(t*Pi/2)*A.y
R.y = C.y   sin((1-t)*Pi/2)*A.y   sin(t*Pi/2)*A.x

Quick checking:

t = 0: R.x = C.x   1 * A.x - 0 = P.x
t = 1: R.x = C.x   0 - A.y = point at the middle perpendicular
t = 2: R.x = C.x - A.x   0 = Q.x
  • Related