# How to make sure that a Point A moving in the direction V reaches at Point B?

Let say I have,

Point A(X1,Y1) moving in the direction V(W, H). I need to make sure that it reaches B(X2,Y2). I think I need to subtract some value in Point A(X1, X2). But not know what? I also sure that the direction is correct.

-

## 2 Answers

You can get the displacement from `A` to `B` by subtraction. I'm not sure if your direction `V` is normalized or not, but if you normalize the direction and normalize the displacement vector, `A` will reach `B` if those vectors are equal.

``````Vector2 displacement = B - A;
displacement.Normalize();
V.Normalize();

if(displacement == V)
{
// A will reach B if you get in here
}
``````

Note: I'm rusty on my XNA so the specific functions you may need to call may be a little off, but the concept should work.

Post-clarification Edit:

``````V.Normalize();
float distance = 10.0f;  //Change this value to whatever distance you want
Point A = B - V * distance;
``````
-
I need to make sure that it must reached there. What I can do with Point A. –  user960567 Apr 16 '12 at 4:46
What is it, specifically, that you need to calculate? Do you mean that you have `A` and `B` and need to calculate `V`? –  chaosTechnician Apr 16 '12 at 4:48
Your XNA is perfectly fine, but since vectors store floating point values you'd have to do an almost-exactly-equal check (because of ye olde classic difference of one millionth). –  doppelgreener Apr 16 '12 at 4:49
No, I need to make sure that Point B is reached. I need to do something with Point A. I cannot change Vector V. I cannot change Point B. –  user960567 Apr 16 '12 at 4:50
So... you want to move point `A` in direction `V` (toward `B`)? Have you tried `A += V`? –  chaosTechnician Apr 16 '12 at 4:52

If I understand correctly, you want a point close to `A` such that moving from that point in the direction `v` will eventually reach `B`.

The point closest to `A` is the projection of `A` on the line `(B,v)`. It is computed as follows:

``````newA = B - dot(B - A, V) / dot(V, V) * V;
``````

-
Is dot means dot product? If no then can you please explain dot method in language agnostic way. –  user960567 Apr 17 '12 at 15:33
@user960567 yes, `dot()` is meant as the dot product. –  Sam Hocevar Apr 17 '12 at 15:37
Can you please explain how you found this formula? –  user960567 Apr 17 '12 at 18:23
@user960567 it's pretty straightforward from the projection of vector AB on the line (B,v) –  Sam Hocevar Apr 17 '12 at 19:03
Also, why you are subtracting from Point B. –  user960567 Apr 18 '12 at 5:23