MATLAB: How to find coordinates of points that are placed on a line with specific distance from first point of the line

coordinatespoints

I tried this: solve(-(y1-y0)*x+(x1-x0)*y+(y1-y0)*x0-(x1-x0)*y0,sqrt((x0-x)^2+(y0-y)^2)-10); But the result of solve is 2 points and I need just the point on my segment. As I need to use it in a loop I can't choose the one on the segment and delete another one. I wonder is there another way different from solve to do this?

Best Answer

If you want a particular distance D away from (x0,y0) along the line connecting (x0,y0) to (x1,y1) then
xyd = sqrt((x1-x0).^2+(y1-y0).^2);
x = x0 + D .* (x1-x0)./xyd;
y = y0 + D .* (y1-y0)./xyd;
Related Question