Different values for same formula

H

Hugh Janus

Hi all, does anyone know why the following code gives me totally
different results when running on the Windows Mobile 5 emulator and a
real Windows Mobile 6 device? I am trying to find out the distance in
metres between 2 GPS points. It works correctly on the emulator but
the WM6 device gives bizarre values!

Values given are: WM5: 0.84912711886472536 & WM6: 50481

Call to function: CalculateDistance(40.44717, -3.63763, 40.44717,
-3.63762)

Please help as I am totally lost! I am using Visual Studio 2005 + VB
with the 2.0 compact framework.

TIA



Private Function CalculateDistance(ByVal Lat1 As Double, ByVal
Lon1 As Double, ByVal Lat2 As Double, ByVal Lon2 As Double) As Integer


Dim a, b, c As Double

' 1 Degree is 69.096 miles, 1 mile is 1609.34 m

a = Math.Cos(Lat1 * Math.PI / 180) * Math.Cos(Lat2 * Math.PI /
180) * Math.Cos(Lon1 * Math.PI / 180) * Math.Cos(Lon2 * Math.PI / 180)
b = Math.Cos(Lat1 * Math.PI / 180) * Math.Sin(Lon1 * Math.PI /
180) * Math.Cos(Lat2 * Math.PI / 180) * Math.Sin(Lon2 * Math.PI / 180)
c = Math.Sin(Lat1 * Math.PI / 180) * Math.Sin(Lat2 * Math.PI /
180)

If (a + b + c) >= 1 Or (a + b + c) <= -1 Then

CalculateDistance = 0

Else

CalculateDistance = Convert.ToInt32(Math.Acos(a + b + c) *
6371000)

End If

End Function
 
O

\(O\)enone

Hugh said:
Hi all, does anyone know why the following code gives me totally
different results when running on the Windows Mobile 5 emulator and a
real Windows Mobile 6 device?

Have you tried getting the code to display the values of the a, b and c
variables after it has calculated each one?

If they are all showing different results between the two platforms, try
getting it to display the values of the individual trig functions that are
being used to calculate the those values.

Once you have broken it down to the individual element that is causing the
problem, it will probably be easier to try to figure out how to correct it.
 
H

Hugh Janus

Have you tried getting the code to display the values of the a, b and c
variables after it has calculated each one?

If they are all showing different results between the two platforms, try
getting it to display the values of the individual trig functions that are
being used to calculate the those values.

Once you have broken it down to the individual element that is causing the
problem, it will probably be easier to try to figure out how to correct it.

Hi, thanks for the fast response. Values a,b and c all differ. For
some reason WM6 is calculating the Math functions differently. Unless
this is a problem with the emulator although the code running in the
emulator is giving the value i expect.

High
 
G

Guest

You could always do the calculation yourself to be sure it's right - it's a
simple Great Circle calculation.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top