How to code this math

D

dave

Access 2003


=ACOS(SIN([Lat1])*SIN([Lat2])+COS([Lat1])*COS([Lat2])*COS([Lon2]-[Lon1]))*6371

Where Lat1, Lon1, Lat2, Lon2 are values in a table (So they will be fields)

Is this math that Access can do?

Is it as simple as dropping the formula in the control source?

Any pointers here would be much appreciated.

tx
Dave
 
A

Allen Browne

The basic trig. functions are built into VBA, but not ACos().

You could add something like this:
Function ArcCos(X As Double) As Double
' Inverse Cosine
If X = 1 Then
ArcCos = 0
ElseIf X = -1 Then
ArcCos = -PI()
Else
ArcCos = Atn(X / Sqr(-X * X + 1)) + PI() / 2
End If
End Function

That comes from a sample database MS released back in 1995, called
neatcode.mdb:
http://support.microsoft.com/kb/148402
There was a more recent version, but I don't have the link.
That database also has a module for Latitude/Longitude - particularly useful
for converting units and calculating GreatArcDistance().
 
D

dave

Thanks very much.

Your code will help - but I am hoping the L/L moduial will be what I am
needing already.

dave
 
C

Chuck

Access 2003


=ACOS(SIN([Lat1])*SIN([Lat2])+COS([Lat1])*COS([Lat2])*COS([Lon2]-[Lon1]))*6371

Where Lat1, Lon1, Lat2, Lon2 are values in a table (So they will be fields)

Is this math that Access can do?

Is it as simple as dropping the formula in the control source?

Any pointers here would be much appreciated.

tx
Dave

Check the help files for Derived Math Functions.
Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

Chuck
--
 

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