Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep
<a href="http://www.technohost.net/" target="_blank" rel="nofollow">Web Hosting</a> | <a href="http://www.reviewmovie.net" target="_blank" rel="nofollow">Review Movie</a>
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep
SCJP
Visit my download page
SCJP
Visit my download page
Originally posted by Randall Twede:
but earth is sphere not circle so that is wrong. i dont know correct formula and it isnt important enough for me to find it.
[ November 09, 2002: Message edited by: Randall Twede ]
Meadowlark Bradsher
SCJ2P, IBM XML V1, Series 7/63
SCJP
Visit my download page
Meadowlark Bradsher
SCJ2P, IBM XML V1, Series 7/63
If you need greater accuracy, you must use the exact distance calculation. The exact distance calculation requires use of spherical geometry, since the Earth is a sphere. The exact distance calculation also requires a high level of floating point mathematical accuracy - about 15 digits of accuracy (sometimes called "double-precision"). Many computer languages do not provide sufficient accuracy for this calculation. In addition, the trig math functions used in the exact calculation require conversion of the latitude and longitude values from degrees to radians. To convert latitude or longitude from degrees to radians, divide the latitude and longitude values in this database by 180/pi, or 57.2958. The radius of the Earth is assumed to be 6,378 kilometers, or 3,963 miles.
If you convert all latitude and longitude values in the database to radians before the calculation, use this equation:
Exact distance in miles = 3963 * arccos[sin(lat1) *
sin(lat2) + cos(lat1) *
cos(lat2) * cos(lon2 - lon1)]
If you do NOT first convert the latitude and longitude values in the database to radians, you must include the degrees-to-radians conversion in the calculation. Substituting degrees for radians, the calculation becomes:
Exact distance in miles = 3963 * arccos[sin(lat1/57.2958) *
sin(lat2/57.2958) +
cos(lat1/57.2958) *
cos(lat2/57.2958) *
cos(lon2/57.2958 - lon1/57.2958)]
OR
Distance = acos(sin(lat1)*sin(lat2)+cos(lat1)*
cos(lat2)*cos(long2-long1)) * r
Where r is the radius of the earth in whatever units you desire.
r=3437.74677 (statute miles)
r=6378 (kilometers)
r=3963 (normal miles)
If the computer language you are using has no arccosine function, you can calculate the same result using the arctangent function, which most computer languages do support. Use the following equation:
Exact distance in miles = 3958.75 * arctan[sqrt(1-x^2))/x]
where x = [sin(lat1/57.2958) * sin(lat2/57.2958)] +
[cos(lat1/57.2958) *
cos(lat2/57.2958) *
cos(lon2/57.2958 - lon1/57.2958)]
If your distance calculations produce wildly incorrect results, check for these possible problems:
1. Did you convert the latitude and longitude values from degrees to radians? Trigonometric math functions such as sine and cosine normally require conversion of degrees to radians, as described above.
2. Are the equations implemented correctly with necessary parentheses? Remember the old math precedence rule: MDAS - multiply, divide, add, subtract.
3. Does your computer language provide sufficient mathematical accuracy? Many languages simply do not provide the required floating point precision. For best results, you need about 15 digits of accuracy. Older versions of Basic, for example, often provide much less accuracy than required for the exact distance calculation.
4. Did you retain decimal points in the latitude and longitude values? When you imported the data into your database program, you may have lost the decimal point during the importation of latitude and longitude values.
Meadowlark Bradsher
SCJ2P, IBM XML V1, Series 7/63
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
Meadowlark- it looks like you're multiplying where you should be dividing. All the South-pole solutions should be in the range
1 < x <= 1.159154943
Meadowlark Bradsher
SCJ2P, IBM XML V1, Series 7/63
SCJP
Visit my download page
Originally posted by Randall Twede:
i do see now how there are an infinite number of answers. good work meadowlark.
Meadowlark Bradsher
SCJ2P, IBM XML V1, Series 7/63
Originally posted by <Simpler Answer>:
Consider the latitude (say, L) near the south pole that is exactly 1km in length. That is, if you walk on that latitude for 1 km, you circle around the south pole and come back to the same point where you started. Now take "any" point on this latitude and go north for 1 km. to a point say X (there will be infinite such possiblities). The set of all such X points is your answer, other then the north pole.
Reason: If you start from X and go south 1km. you reach the latitude L. Since L is 1km in length, going west for 1km, brings you back to that same point. Then you go back north 1km and you reach your starting X.
Originally posted by <bill>:
This is exactly my answers above.
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
"Simpler Answer"
Consider the latitude (say, L) near the south pole that is exactly 1km in length.
Ah, yes, that would be what Meadowlark and I have been talking about. Don't forget the other solutions for latitudes of length 1/2 km, 1/3 km, 1/4 km etc.
[/QB]
Meadowlark Bradsher
SCJ2P, IBM XML V1, Series 7/63
Originally posted by Jim Yingst:
"bill":
1 + 2*pi*R/360 * Math.asin(1/R/2/pi)
Pardon me? What do you think you're doing? It looks like you're confusing degrees and radians (hint: degrees are completely useless in this problem - get rid of them).[/QB]
"I'm not back." - Bill Harding, Twister
Originally posted by <Simpler Answer>:
Agreed!!!
(i did not read it before as it involved way too many numbers)
SCJP
Visit my download page
Originally posted by Jim Yingst:
Sigh. Let's try again. I for one do not understand where you got yor formula, and I don't think you do either. Can you provide any explanation for it? In particular, why is there a "360" in there? Is it part of a conversion between degrees and radians? Is any other quantity in your formula measured in degrees?
You may note that I've already provided an answer of my own to the original problem, with explanation. The formulas I used are rather similar to the ones you made up, but with some key differences. If you disagree with what I said, feel free to explain why, or ask for clarification as I have from you. If you can't be bothered to clarify, why should anyone assume you have any idea what you're talking about?
Originally posted by Jim Yingst:
Don't forget the other solutions for latitudes of length 1/2 km, 1/3 km, 1/4 km etc.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |