LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate the angle of the next turn

Hi,

 

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
(3,092 Views)
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
(3,088 Views)

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. 😉

Message 3 of 8
(3,082 Views)
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
(3,081 Views)
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
(3,080 Views)
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
(3,063 Views)

Hi Luc,

 

yes Smiley Wink 

Or you calc the difference of theta...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 8
(3,038 Views)
You can simply divide the two complex numbers and the theta of the result will be the angle you want. 😉
Message 8 of 8
(3,029 Views)