Point on line segment Distance from point

I am looking for an algorithm (or algorithm name) that will find a point in a line segment, if such a point exists, that is, some given distance from another point not located on the segment.

ie There are three points A , B , C ; and possibly a fourth D . Where AB is a line segment, and point C is another point somewhere off in the line segment AB . Locate the point D , if there exists a point that appears on the line segment AB , which is a predetermined distance distancefrom the point C .

+3
source share
2 answers

Look here: Intersection of a circle line

C- these are circles, and distance- radius.

Note that there can be two resulting points and that you should check if the point is really on your line (or on the line that you will get by expanding it).

+5
source

I thought about this for too long and could not find a simple answer anywhere, so I decided that I would post it here and save a lot of time. Despite the fact that the original post is out of date, I'm sure someone posted a simple answer long ago. That would save me a couple of days of experimentation.

public static Point PointFromEndOfLine(Point start, Point end, double distance)
{
    double x = end.X-start.X;   
    double y = end.Y-start.Y;
    double z = Math.Sqrt(x * x + y * y);  //Pathagrean Theorum for Hypotenuse
    double ratio = distance / z;
    double deltaX = x * ratio;
    double deltaY = y * ratio;

    return new Point(end.X-deltaX, end.Y-deltaY);
}

startPoint (x, y) endPoint (x, y) ( . , . startPoint endPoint, , . startPoint endPoint, startPoint endPoint .

, , - " ". . , X, x, y, z , , , .

: x/X == y/Y == z/Z

, -.

+5

Source: https://habr.com/ru/post/1775993/


All Articles