My Math Forum Haversine Formula

 Trigonometry Trigonometry Math Forum

 June 4th, 2018, 07:36 AM #1 Newbie   Joined: Jun 2018 From: Milwaukee Posts: 5 Thanks: 1 Haversine Formula Hey guys, I'm programming an Arduino to do some fun tasks for me; one is to calculate a heading/bearing based on current position (current being point A) and a destination (destination being point B). Now I'm using (trying) haversign to do this, and I'm sure I'm not doing it correctly. Any instance I manage to expect a negative value, it kicks me a positive value of the exact amount. So I feel like a) my math is flat out wrong b) my understanding is wrong and this formula never yields a positive value and it is procedurally added by a method I'm not aware of. I will list a specific set of parameters below should anyone want to help me out. Below also I will list a website where you can set two points and it will auto-calculate. The example of points listed below should yield roughly -17.9*** https://www.igismap.com/map-tool/bearing-angle Here are the points LatA: 49.077478 LonA: 67.162589 LatB: 42.799419 LonB: -88.140146 Haversign is as follows: X = cos Î¸b * sin âˆ†L Y = cos Î¸a * sin Î¸b â€“ sin Î¸a * cos Î¸b * cos âˆ†L Î² = atan2(X,Y) Last edited by skipjack; June 5th, 2018 at 06:58 AM.
 June 5th, 2018, 06:59 AM #2 Global Moderator   Joined: Dec 2006 Posts: 19,702 Thanks: 1804 It's spelt haversine, which may be abbreviated to hav in equations.
June 5th, 2018, 07:50 AM   #3
Newbie

Joined: Jun 2018
From: Milwaukee

Posts: 5
Thanks: 1

Quote:
 Originally Posted by skipjack It's spelt haversine, which may be abbreviated to hav in equations.
I see this was a waste of my time

 June 5th, 2018, 11:19 AM #4 Global Moderator   Joined: Dec 2006 Posts: 19,702 Thanks: 1804 Not necessarily. I was pushed for time, so my reply was limited. Why did you mention haversine when the equations you gave don't use it? I did the calculations (using your equations) and got -17.9$^\circ\!$ approximately, as expected. What programming language were you using?
 June 5th, 2018, 12:29 PM #5 Senior Member   Joined: Aug 2012 Posts: 2,040 Thanks: 581 The versine is twice the haversine. Today I learned!! https://en.wikipedia.org/wiki/Haversine_formula
June 6th, 2018, 11:33 AM   #6
Global Moderator

Joined: Dec 2006

Posts: 19,702
Thanks: 1804

Quote:
 Originally Posted by hanslanda . . . a positive value of the exact amount.
If you gave âˆ†L a positive sign (it should be negative for your data), that would explain the sign error in your calculated result.

 June 12th, 2018, 11:15 AM #7 Newbie   Joined: Jun 2018 From: Milwaukee Posts: 5 Thanks: 1 My apologies. I'm checking my math again. Perhaps i'm not understanding Delta L correctly. I will try again and get back! Oh also i'm using python, but i got the exact same numbers in excel, which leads me to believe its my math. My basic understanding of delta was more or less absolute difference. How exactly do you calculate Delta L? Last edited by hanslanda; June 12th, 2018 at 11:19 AM.
June 12th, 2018, 01:17 PM   #8
Newbie

Joined: Jun 2018
From: Milwaukee

Posts: 5
Thanks: 1

Quote:
 Originally Posted by skipjack If you gave âˆ†L a positive sign (it should be negative for your data), that would explain the sign error in your calculated result.
It appears I was able to get the correct answer by subtracting LongB by LongA with no absolute positive. This was vague in the formula description I read.

Still doesn't make a whole lot of sense to call out a Delta if you're expecting a negative value, in my opinion.

To me 'sin deltaL' = sin(abs(A-B))

In reality it expects = sin(b-a)

Is this your understanding as well Skipjack?

PS. Is skipjack in reference to the sub?

 Tags formula, haversign, haversine

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post oang Trigonometry 0 September 2nd, 2015 11:51 PM nsrmsm Number Theory 7 October 15th, 2012 05:36 AM silvercats Calculus 4 June 7th, 2011 01:10 AM agro Probability and Statistics 3 August 27th, 2009 06:17 AM nicromonicon Algebra 0 June 25th, 2009 02:18 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top