Explanation:
looking at the graph I can see it right there :
P is point (2, 3).
why ? you see how the slope of the line makes it cut through small 2×1 rectangles to reach the next point with integer coordinates.
it goes through (0, 2), (2, 3) until it reaches B.
it crosses 3 such rectangles.
now look at the requested ratio 2:1. a ratio x:y tells us that the whole is shot into x+y equally sized parts. therefore, in our case, we have 2+1 = 3 parts.
that means 2 of these parts are between A and P, and the remaining 3rd part is between P and B.
remember, where we just said the number 3 ? yes, the number of 2×1 rectangles that are crossed bergen A and B.
so, P is the point at the end of crossing the second rectangle of the 3, which is (2, 3).
and now, as a second approach, we do the theoretical calculation.
the ratio 2:1 tells us to split this distance into 2+1 = 3 equally sized parts.
one part = ⅓ of the whole distance.
two parts = ⅔ of the whole distance, which we need starting at A.
A = (Ax, Ay) = (-2, 1)
B = (Bx, By) = (4, 4)
P = (x, y)
the beauty here is that the ratio applies now not only to the total length but also to both individual dimensions (x and y). it is scaling (projection).
so the coordinate of every dimension is simply the ratio-scaled difference (between the corresponding A and B coordinates) added to the A coordinate (or subtracted from the B coordinate).
but we start at A, so
x = Ax + (Bx - Ax)×⅔ = -2 + (4 - -2)×⅔ = -2 + 6×⅔ =
= -2 + 4 = 2
y = Ay + (By - Ay)×⅔ = 1 + (4 - 1)×⅔ = 1 + 3×⅔ =
= 1 + 2 = 3
therefore, P = (2, 3).