Search code examples
javaandroidmathgeometry

How to find a point in a line in java?


I am trying to do some experiments with path. I have two points (x0,y0) and (x2,y2). Now I have to find a point (x1,y1) that should be some distance from the final point (x2,y2).

For example
Start Point (0,0) End Point (0,5)
Point i want to find is (0,2)

enter image description here


Solution

  • For a line between

    enter image description here

    The point at distance d from the first point, (positive) in the direction of the second point, is given by:

    enter image description here

    Where L is the distance between the two points defining the line:

    enter image description here

    (For your case just take L - d instead of d)