In p5.js I have:
a point with a specific x,y position;
a segment with a point x1, y1 for its start and x2, y2 for its end.
I want to know the point is at a distance less than 2 from any part of the segment.
Is there an equation with a for loop or something to determine if the above is true? Please ask me in the comments if there are any questions. Thanks in advance.
What could be done, knowing the origin and destination points of the line, is to build a function that calculates the position of each of its intermediate points. Once these positions are known, the function
dist(x1, y1, x2, y2)
provided by the p5 library can be used to find out the distance between a given point and each of the points that make up the line.I got excited and made a graphic example. There you can see how the graph is rotated when the slope is greater than 1 or less than -1, so as not to lose precision. The red lines are each distance measurement using the original function and the blue ones are made after rotating the graph ninety degrees.