Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this bearing calculation so inacurate?

Is it even that inaccurate? I re-implented the whole thing with Apfloat arbitrary precision and it made no difference which I should have known to start with!!

public static double bearing(LatLng latLng1, LatLng latLng2) {
 double deltaLong = toRadians(latLng2.longitude - latLng1.longitude);

 double lat1 = toRadians(latLng1.latitude);
 double lat2 = toRadians(latLng2.latitude);

 double y = sin(deltaLong) * cos(lat2);
 double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLong);
 double result = toDegrees(atan2(y, x));
 return (result + 360.0) % 360.0;
}

@Test
 public void testBearing() {

  LatLng first = new LatLng(36.0, 174.0);
  LatLng second = new LatLng(36.0, 175.0);
  assertEquals(270.0, LatLng.bearing(second, first), 0.005);
  assertEquals(90.0, LatLng.bearing(first, second), 0.005);
 }

The first assertion in the test gives this:

java.lang.AssertionError: expected:<270.0> but was:<270.29389750911355>

0.29 seems to quite a long way off? Is this the formula i chose to implement?

like image 263
Greg Avatar asked Feb 09 '10 22:02

Greg


People also ask

How do you determine the reliability of a bearing?

Bearing Rating Life CalculationC = Dynamic Capacity (dN or Lbs) P = Equivalent Bearing Load (N or Lbs) N = Rotating speed in RPM. e = 3.0 for ball bearings, 10/3 for roller bearings.

What is the most common cause of bearing failure?

While it may seem like common sense, standard wear and tear is one of the leading causes of bearing failure. Eventually all bearings fail due to wear, however, excessive load, vibration or force can cause a bearing to wear out long before it should. Most of this excess force is caused by improper installation.


2 Answers

If you've done what you seem to have done and done it correctly you have figured out the bearing of A from B along the shortest route from A to B which, on the surface of the spherical (ish) Earth is the arc of the great circle between A and B, NOT the arc of the line of latitude between A and B.

Mathematica's geodetic functions give the bearings, for your test positions, as 89.7061 and 270.294.

So, it looks as if (a) your calculation is correct but (b) your navigational skills need polishing up.

like image 100
High Performance Mark Avatar answered Nov 10 '22 07:11

High Performance Mark


Are you sure this is due to numeric problems? I must admit, that I don't exactly know what you are trying to calculate, but when you dealing with angles on a sphere, small deviations from what you would expect in euclidian geometry.

like image 31
Jens Schauder Avatar answered Nov 10 '22 07:11

Jens Schauder