Reputation: 141
I have a list of points (x,y coordinates) which describe a path. Suppose {(1,1),(2,2),(5,2)} can be a list of points of a path.
Now, I want to instruct my user the way to move along the path. For example, at each point, there will be a string attached which will describe the user how to go to the next point. It can be something like, "go 90 degree left", "go 35 degree right" etc.
Is there any algorithm or suggested way to do that?
Please let me know if any part of the problem description is not understandable.
Upvotes: -1
Views: 78
Reputation: 13
If your user is at point 1 (x1,y1) and you want him to go to point 2 (x2, y2) then you calculate what is called the position vector. The short answer is that you calculate the position vector's magnitude and angle. The magnitude tells the user how far to move and angle tell him the direction. So,
magnitude = sqrt( (x2-x1)^2 + (y2-y1)^2 )
angle = arc tan( (y2-y1)/(x2-x1))
and then you may want to convert the angle from radians to degrees with angle=angle*(180/pi).
Upvotes: 0