Showing results for 
Search instead for 
Did you mean: 

How to calculate the angle of the next turn




I am currently working on a project which involves using a set of coordinates to control a car. At the moment, these waypoints are input into an array of x and y  and the car is commanded to traverse the line between them.

The problem i have is I cannot work out how, given 3 points, A (being the previous waypoint), B (being the waypoint the car is approaching) and C (being the next waypoint the car will be travelling towards after it has turned) I can calculate whether the car is turning right or left at B.


Thanks, Luc

0 Kudos
Message 1 of 8
You could calculate the slope between A and B and the slope between B and C.  If the slope between B and C is greater than the slope between A and B it is a left turn and vice-versa.
0 Kudos
Message 2 of 8

It might be easier to do all that using complex numbers (RE,IM) instead of number pairs (X,Y). You can get the difference in vector angle, which you then need to fold into a unique range (e.g. 0..360 or -180..180). Half of the range is "right", and the other half is "left".


See how far you get. 😉

LabVIEW Champion. It all comes together in GCentral GCentral
Message 3 of 8
I realized after I posted that slope alone will not be good enough because you also need a positive/negative direction.  You will need to create a heading (0 - 360 degrees) from your x-y coordinates for the A-B path and then for the B-C path.  It takes a fair amount of math, but if the second heading is  anywhere from 0 to -180 from the first heading it is a left turn. If the difference in heading is between 0 and 180 from the first heading to the second heading, it will be a right turn.
Message 4 of 8
That is what i thought, but the problem arises in the fact that it could be travelling either way down a line of the same gradient and therefore this does not give a reliable prediction.
0 Kudos
Message 5 of 8
I have now connected it up so that the differences for A->B (x and y) go into the Re and Im of one complex number, and the same for B->C. Can i then just convert these into polar and compare theta?
0 Kudos
Message 6 of 8

Hi Luc,


yes Smiley Wink 

Or you calc the difference of theta...

Best regards,
CLAD expired, using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 7 of 8
You can simply divide the two complex numbers and the theta of the result will be the angle you want. 😉

LabVIEW Champion. It all comes together in GCentral GCentral
Message 8 of 8