I have 2 points, for example A(1, 30), B(20, 10). I should draw in console the vector with nearest path of *. I should get every point of path, how can I do this?
I have 2 points, for example A(1, 30), B(20, 10). I should draw in console the vector with nearest path of *. I should get every point of path, how can I do this?
There may be various solutions for it. One solution is to iterate (for example using two for loops) over all points between A and B and check whether the line passes through each point.
And you need a criterion to decide whether the line segment AB passes through a specific point P(x,y). For example you can measure the Euclidian distance of point P to line AB. Then the point lies on the line if the distance is smaller than a specific value, say 0.5.
Another criterion to decide whether P lies on AB is to check whether the line AB passes through a 1x1 square centered at P(x,y). The four corners of this square are P1(x-0.5,y-0.5), P2(x-0.5,y+0.5), P3(x+0.5,y-0.5) and P4(x+0.5,y+0.5). To figure out whether the line passes through this square, you can evaluate these four corners and determine whether all lie on the same side of the line. If so, the line does not cross the square and otherwise it crosses the square.
Using each criterion, you will obtain a set of points that are assumed to lie on the line segment.