Cocoa 48-Hour Programming Challenge

Founder
Posts: 1,138
Joined: 2002.04
Post: #1
I'll like to see how many of you are savvy with Cocoa. So here is a challenge for you to be completed in 48-hours.

* Place the link for your app
* We vote for the best
* You show your source code
* No prizes, just glory
* Only ObjectiveC entries
* The time is based on the time of this post.

Challenge: Calculate the Distance Using Latitude and Longitude between two locations.

Anything extra will help your chances, and should give you extra "ohhs and ahhhs" (ie, showing 3d vectors to show the distance, a 3d globe, entering of city names, etc)

Here is the info you need:
Quote:Calculating Distance Using Latitude and Longitude

In this database, the location of ZIP codes is defined in terms of degrees of
north latitude and degrees of west longitude. Because of the spherical shape
of the Earth, calculating the exact distance between two ZIP codes requires
the use of spherical geometry and trigonometric math functions. However, you can calculate an approximate distance using much simpler math functions. For many applications the approximate distance calculation provides sufficient accuracy with much less complexity.

The following approximate distance calculations are relatively simple, but can
produce distance errors of 10 percent of more. These approximate calculations are performed using latitude and longitude values in degrees, as defined in this database. The first approximation requires only simple math functions:

Approximate distance in miles = sqrt(x * x + y * y)

where x = 69.1 * (zip2.lat - zip1.lat)
and y = 53 * (zip2.lon - zip1.lon)

You can improve the accuracy of this approximate distance calculation by
adding the cosine math function:

Approximate distance in miles = sqrt(x * x + y * y)

where x = 69.1 * (zip2.lat - zip1.lat)
and y = 69.1 * (zip2.lon - zip1.lon) * cos(zip1.lat/57.3)

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,371 kilometers, or 3,958.75 miles.

If you convert all latitude and longitude values in the database to radians
before the calulation, use this equation:

Exact distance in miles = 3958.75 * arccos[sin(zip1.lat) *
sin(zip2.lat) + cos(zip1.lat) *
cos(zip2.lat) * cos(zip2.lon - zip1.lon)]

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 = 3958.75 * arccos[sin(zip1.lat/57.2958) *
sin(zip2.lat/57.2958) +
cos(zip1.lat/57.2958) *
cos(zip2.lat/57.2958) *
cos(zip2.lon/57.2958 - zip1.lon/57.2958)]

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(zip1.lat/57.2958) * sin(zip2.lat/57.2958)] +
[cos(zip1.lat/57.2958) *
cos(zip2.lat/57.2958) *
cos(zip2.lon/57.2958 - zip1.lon/57.2958)]

Using the latitude and longitude values provided by this database, you should
be able to obtain distance accuracy of approximately +/- 36 feet.

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.


Good Luck,

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
eww, miles.

*looks for barfing face smiley*
Quote this message in a reply
Member
Posts: 72
Joined: 2006.10
Post: #3
LOL

Damn you with your challenges.

I'm gonna ruin my session 'cause of this... But.. I.. can't... resist... Cry

- Sohta
Quote this message in a reply
Moderator
Posts: 682
Joined: 2002.11
Post: #4
Er...not much warning, eh? Another "I-just-sprung-it-on-you" contest?

My web site - Games, music, Python stuff
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #5
Think of it like a pop-quiz.

OSC... extra ohhs for people who know kilometers and miles. Wink

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Moderator
Posts: 437
Joined: 2002.09
Post: #6
Carlos, next time you should give them 48 hours to write a program that, given a bunch of wishlists of winning developers, will calculate who gets what. And then contacts each of the sponsors automatically. :-)

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Moderator
Posts: 592
Joined: 2002.12
Post: #7
Being professional about this, I thought I had better check the specs of this project before commencing it.

The app you are after takes 2 points as input and returns the distance between the two.

The talk of databases is not relevant, just it happens to be in the reference document you provided?

(Now I just wonder if this is going to be so realistic that the client does not respond until the deadline is 1 hour away Wink )
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #8
You're on. It's been a long time since I've done any Cocoa hot-wiring.
Quote this message in a reply
Member
Posts: 201
Joined: 2002.06
Post: #9
No can do this time. But... I love things like this. I think these are exactly the sorts of things we need to see more often here. Do it more!
Quote this message in a reply
Moderator
Posts: 437
Joined: 2002.09
Post: #10
geezusfreeek Wrote:No can do this time. But... I love things like this. I think these are exactly the sorts of things we need to see more often here. Do it more!
How about: winner of this challenge gets to help pick the next 48-hour challenge?

(Caveats: Carlos gets final say over the appropriateness of the challenge. And people who set the challenge have to sit it out.)

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Member
Posts: 201
Joined: 2002.06
Post: #11
How about each time somebody wins one he is handicapped a couple of hours for later ones (he has to send it in sooner)? Keep the competition going a little more? Let people other than the super-elite have a chance?
Quote this message in a reply
Member
Posts: 328
Joined: 2002.04
Post: #12
BeyondCloister Wrote:The app you are after takes 2 points as input and returns the distance between the two.

The talk of databases is not relevant, just it happens to be in the reference document you provided?

Everything seems to imply that the program will just take coordinates and return a distance. Carlos doesn't provide you with zip codes and corresponding coordinates so I don't think he expects you to use a database, and that it is indeed just part of the reference document. But listening to me would be taking advice from someone who knows no more than you do, so you can still cross your fingers and hope Carlos replies before the deadline Rasp

Of course if you do build in database support I'm sure you'd get all kinds of 'leet props Ninja Or something Blush
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #13
Use what you can, or what you want. I'm very flexible. As for voting, place your link to download and after we all try them, we can all vote on them.

I admit that this idea came to me in about 30 seconds. I was searching for GIS data for Mexico, since I have to make various GIS maps of Mexico for my company's next project. And so I came across this, and thought, "that would make for an interesting programming challenge."

I'm keen to run more of them in the future, and will think them through in advance much more. Having people suggest the next contest is good. I have a long list of stuff that I would like to see worked on. Little stuff that can perhaps be useful to learn from, for game programming.

Anyhow, good luck. If you have a question on something that is not clear, like the database, simply state what you think, and if everyone agrees, then we make it "so."

Cheers,

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #14
I was just thinking -- wouldn't it be cool to use such a little app, anjd then enter everyone's lat/long. and then we all can see who is nearest to us, and who is furthest from us. Wink Would be useful if anyone here plans to go around the world and stay at the home of a forum member. Wink

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
⌘-R in Chief
Posts: 1,261
Joined: 2002.05
Post: #15
10 bucks says Carlos needed an application to do this. Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  GamePress Greatest Game Challenge VPrime 1 1,257 Oct 28, 2013 06:15 PM
Last Post: VPrime
  Moscrif game development challenge Turok 0 2,615 Oct 1, 2012 08:38 AM
Last Post: Turok
  Zero-hour game jam JustinFic 7 7,075 Nov 9, 2011 12:04 AM
Last Post: funkboy
  Google AI Challenge OneSadCookie 13 12,060 Dec 2, 2010 06:42 PM
Last Post: PowerMacX
  Announcing the Macworld 2010 GameSalad Challenge! GameSalad 3 6,403 Dec 30, 2009 06:23 PM
Last Post: pinguoren