so...I have this program that I am working on (learning) in which I have to have a bus that follows road line segments that the user draws (linear). 'n I have no clue how to write it.
I came up with the line equation derived from two endpoints: Y=x*(y2-y1)/(x2-x1)
In the program when the vehicle hits an intersecting road, it turns RIGHT. when the vehicle hits the endpoint of the road, it reverses direction. [if there is no way to turn right, it must continue to the endpoint and reverses direction]
I want the users to be able to draw the roads by clicking once for the beginning and the end of the line segments.
For intersecting a line, I was advised of plugin in the X and Y value of the bus into the equation Y=x*(y2-y1)/(x2-x1).
if (x*dy+c*dx-y*dx) is very close to zero, then the point is close to the infinite line. However, I don't know how to deal with line segments (non-infinite lines)
Well, loop over x from x1 to x2 (the end points of the segment), and computer, for each value of x, the corresponding value of y with the formula you show. Then you can draw the bus at these coordinates.
Leave a comment on PhiLho's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic