I have a list of waypoints (latitude, longitude) and sometimes, there are wrong waypoints in that list.
My Problem is: How do i identify those waypoints?
I tried calculating the headings of each pair of waypoints, and then throwing those out where the change in heading is way too big.
// $heading is the heading of the previous waypoint pair
// $h is the heading of the current waypoint pair
$turn = null;
if ($heading !== null && $h !== null) {
$a = abs($heading - 180);
if ($b < 0)
$b += 360;
if ($a < 0)
$a += 360;
$turn = abs($a - $h);
}
This attempt didn't work out as some faulty waypoints were still not detected or correct waypoints were wrongly detected.
Does someone have an idea how to reliably figure out which ones are faulty?
Edit: Here are some datasets to test:
$data = [
[14.5922222137, -60.9963874817], // First waypoint can't be faulty as it is the start
[14.58529722, -61.03905556],
[-23.16040556, 29.58556389], // faulty waypoint
[14.83583333, -61.30305556],
[32, -60],
[51.00166667, -61.99916667],
[52.66333333, -61.65361111],
[53.17405278, -60.75461944],
[53.3191680908, -60.4258346558] // Last waypoint can't be faulty either as it is the end
];
$data2 = [
[36.0800552368, -115.152252197], // First waypoint can't be faulty as it is the start
[36.07603889, -115.12513611],
[36.07641111, -114.99773889],
[36.07364722, -114.94283889],
[36.0379, -114.77057222],
[34.62250278, -107.80684444],
[34.39397778, -106.69660556],
[34.36862778, -105.82488333],
[23.84245, 120.25903611], // faulty
[29.99604444, -94.30452222],
[29.66479722, -92.08668333],
[28.66666667, -88.66666667],
[24.56361111, -81.01666667],
[24.45256111, -78.67836944],
[23.66087778, -77.20931111],
[15.83413889, -67.49952778],
[14.24444444, -65.77944444],
[13.90027778, -64.30277778],
[14.547, -61.27663889],
[14.5922222137, -60.9963874817] // Last waypoint can't be faulty either as it is the end
];