the vehicle follows linear roads drawn interactively by the users??
in
Programming Questions
•
2 years ago
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)
I appreciate your help
Thanks :)
1