tester0101
tester0101

Reputation: 13

moving in a circular motion from one point to another

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.sstatic.net/N1ykX.png

Upvotes: 1

Views: 187

Answers (1)

MBo
MBo

Reputation: 80187

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

Upvotes: 2

Related Questions