I have two points, for which I know Cartesian coordinates. I want to move one towards the other over specific distance.
That's about the same as saying I want the distance between the points equal to specific value:
How do I achieve that? I think it's the basic in any game and vector operations, moving Cartesian point towards specific location...
I tried derivating this using high school algebra but it doesn't look too good. In the end, I end up with quadratic equation. Check my progress:
I know desired distance between A and B. I know A's coordinates and I know B's coordinates ratio:
- $distance = \sqrt{(A_x-B_x)^2+(A_y-B_y)^2}$
- $B_x = B_y*q$
The second equation comes from the fact that as long as we move point over straight line, it's coordinates are function of linear equation and their ratio is constant. In math: $B_x/B_y = q$ where $q$ is constant value.
First I substitute $B_y*q$ for $B_x$ and then $(...)^2$ whole equation:
$distance = \sqrt{(A_x-B_y*q)^2+(A_y-B_y)^2}$
I used wolfram to simplify this:
$distance^2 = (A_x-B_y*q)^2+(A_y-B_y)^2$
This is Wolfram's result:
$distance^2 = B_y^2*(q^2 + 1) - 2*A_x*B_y*q - 2*B_y*A_x.y + A_y^2 + A_x^2$
I formatted it to look like typical quadratic equation:
$B_y^2*(q^2 + 1) - B_y*(2*A_x*q + 2*A_y) + A_y^2 + A_x^2 - distance^2 = 0$
Now this is where it's getting messy, so I'll make standard quadratic equation substitution:
$a = q^2 + 1$
$b = 2*A_x*q + 2*A_y$
$c = A_y^2 + A_x^2 - distance^2$
Finally:
$$B_{y 1,2} = \frac{-b +- \sqrt{b^2 - 4*a*c})}{2*a}$$
And I just don't want to even try to de-substitute that. I mean what of it, I need one result, not two of them...