Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math - Questions and Answers from our Archives
_____________________________________________
Associated Topics || Dr. Math Home || Search Dr. Math
_____________________________________________

What's 'Arccos'?

Date: 06/17/2001 at 22:20:10
From: Daniel 
Subject: What's 'Arccos'?

I'm trying to write a program in Visual Basic 6 about the distance 
calculation between two cities. I found a equation that you wrote in 
1995, but I can't understand some parts.

You said that with the latitudes and longitudes of two places (cities), 
when substituted into the equation:

Arccos = {[cos(a1) cos(b1) coa(a2) cos(b2)] + [cos(a1) sin(b1) cos(a2) 
sin(b2)] + [ sin(a1) sin(a2)]}/360*2Pi*r

I'd like to ask you what you mean by Arccos and Pi in this equation.

Any help given by 'The Swat Team' will be greatly appreciated.


Date: 06/18/2001 at 08:14:46
From: Doctor Jerry
Subject: Re: What's 'Arccos'?

Hi Daniel,

pi means the constant 3.141592654...  It is the ratio of the 
circumference of a circle to its diameter, which turns out to be the 
same for every circle. You can read about it in the Dr. Math FAQ on 
Pi:

  http://mathforum.org/dr.math/faq/faq.pi.html   

arccos is the name of the inverse cosine function, which is sometimes 
written as cos with an exponent of -1.

You have written, in part, 

Arccos = {[cos(a1) cos(b1) ...

This can't be correct, because Arccos alone doesn't have a meaning in 
this equation. You must mean the arccos(s) of something.

Look under the worked examples on the Aviation Formula VI.30 page by 
Ed Williams:

  http://www.best.com/~williams/avform.htm#LL   

- Doctor Jerry, The Math Forum
  http://mathforum.org/dr.math/   


Date: 06/18/2001 at 12:03:22
From: Doctor Peterson
Subject: Re: What's 'Arccos'?

Hi, Daniel.

I want to add a couple of things.

The 'arccos' function is the inverse of the cos function. That is, if 
it is true that

  cos(a) = x

then it is also true that

  arccos(x) = a

For example, 

  cos(pi/4 radians) = cos(45 degrees) = 0.707

so

  arccos(0.707) = 45 degrees = pi/4 radians

Second, in Visual Basic, the arccos function has to be implemented 
using the arctangent function Atn. Microsoft provides equivalents of 
the arccos and other functions here:

  How to Derive Inverse (ARC) and Hyperbolic Trig Functions -
  Microsoft Corporation
   http://support.microsoft.com/support/kb/articles/Q28/2/49.asp    

They give

  ARCCOS(Y) = -ATN(Y/SQR(1-Y*Y)) + Pi/2

If y is 1 or -1, this will fail, so you should protect against that 
case. 

Visual Basic help suggests this definition of Pi:

  Dim pi
  pi = 4 * Atn(1)

Third, there are several formulas for geographical distance in our 
archives. Here are three, which I found by searching the archives for 
"distance latitude longitude":

  Using Longitude and Latitude to Determine Distance
   http://mathforum.org/dr.math/problems/longandlat.html   

  Distance using Latitude and Longitude
   http://mathforum.org/dr.math/problems/reed12.31.97.html   

  Deriving the Haversine Formula
   http://mathforum.org/dr.math/problems/neff.04.21.99.html   

The first is probably what you found; don't miss the comments at the 
bottom about radians and degrees; this will be true of Basic, which 
uses radians.

The last uses "atan2(y,x)", which in Visual Basic will be replaced 
with "atn(y/x)" - again with some tricks needed for negative values. 
This is probably the best for you to use, for several reasons 
described there.

Looking for a site that might help you use the limited set of 
functions available in Visual Basic, I ran across this page

  http://vbgraphic.altervista.org/geoalgo.htm#arctangent   

which gives a short version of atan2 you can use:

  Public Function Atn2(X As Double, Y As Double) As Single
  Const NearZero = 0.000000001
  If Y = 0 Then Y = NearZero
  Atn2 = (Atn(Abs(X) / Abs(Y)) * Sgn(X) - 3.141592653 / 2) * Sgn(Y)
  End Function

Note that this uses a different order of X and Y; it also gives the
wrong sign for the answer. I suggest this instead, for your purposes:

  Public Function Atn2(Y As Double, X As Double) As Double
  Const NearZero = 0.000000001
  Const Pi = 4 * Atn(1)
  If X = 0 Then X = NearZero
  Atn2 = (Pi / 2 - Atn(Abs(X) / Abs(Y)) * Sgn(X)) * Sgn(Y)
  End Function

There are many other ways to accomplish the same thing.

Finally, if you are going to be writing programs of this sort much, it 
would be an excellent idea to get a book on basic trigonometry so you 
will have the background needed to properly understand what you are 
doing.

- Doctor Peterson, The Math Forum
  http://mathforum.org/dr.math/   
    
Associated Topics:
High School Calculators, Computers
High School Trigonometry

Search the Dr. Math Library:


Find items containing (put spaces between keywords):
 
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/