Here is a picture of the problem:
Note: I found 2 more questions that are very similar or equal, but I canβt figure it out: Looking for the coordinates of a point between two points?
How to find a point located between two points forming a segment using only the partial length of the segment?
PS This is not homework, I need it for a programming problem, but I forgot my math ...
Assuming A is a position vector, B is a position vector, and maxLength is the maximum length you allow.
A and B are Vector2 (since you noted this question xna ).
A
B
Vector2
// Create a vector that describes going from A to B var AtoB = (B - A); // Make a vector going from A to B, but only one unit in length var AtoBUnitLength = Vector2.Normalize(AtoB); // Make a vector in the direction of B from A, of length maxLength var AtoB1 = AtoBUnitLength * maxLength; // B1 is the starting point (A) + the direction vector of the // correct length we just created. var B1 = A + AtoB1; // One liner: var B1 = A + Vector2.Normalize(B - A) * maxLength;