3
Your mission, should you choose to accept it, is to write code for a GPS receiver.
Input
- The current time, as nanoseconds from the Unix epoch. [EDIT: This is optional, please state whether you require it]
- Four satellite signals, in the following format:
- The time the signal was sent, as nanoseconds from the Unix epoch. You must be able to handle dates up to and including 2020.
- The location of the satellite, as Cartesian coordinates, in metres. You must be able to handle values that fit into a signed 32-bit integer (-2,147,483,648 to 2,147,483,647). Only integer coordinates will be given. You may assume valid input (i.e. your position can be calculated)
Input can be provided from command-line arguments, standard input or equivalent, but not from a variable. The input can have any separator characters in it; please specify what your input format is.
Output
The coordinates of your receiver, to the nearest 1000 metres, using 299,792,458 m/s as the speed of light. Again, I will be lenient with the output format: any separators are acceptable.
Example
Input
1412349052664203400
[1412349052692915310,2267943, 13318342, 0]
[1412349052698278110,-3757960, 3500627, 0]
[1412349052691548521,4425976, -1533193, 3469445]
[1412349052687888295,10622179, 11246951, 84184]
Output
(6223615, 5673496, 0)
I have made a GeoGebra notebook for this example. Please excuse my extremely sloppy GeoGebra skills.
How GPS Works
Because the speed of light is finite, there will be a difference between your current time and the time the satellite sent the signal.
- Use the difference to calculate the distance to the satellite, d.
- You are clearly located somewhere on the surface of a sphere, centered on the satellite, with radius d.
- Once you have two satellites and two spheres, you have to be located somewhere on the intersection of the two sphere surfaces, which is a circle.
- Adding another satellite reduces the possible positions to just two points, where all three sphere surfaces intersect.
- The fourth satellite allows you to decide on a specific one of these points. Your task is to calculate the location of this point, where all four spheres intersect. Since you assume valid input, such a point does exist.
Rules
- Standard loopholes are banned.
2I have two programs written from testing, but neither are anywhere close to golfed solutions :D Hopefully I'll submit one in the next few days. – stokastic – 2014-10-03T19:24:00.700
Why not one more satellite but without the current time? Normally you do not have a perfectly synced timer on your GPS. – flawr – 2014-10-03T20:47:01.293
@flawr Does that work? Thanks, but I won't change it now – None – 2014-10-03T20:55:56.297
Thats the way it does works=) At the moment I am still getting
1.0e+006 *(6.2236,5.6735,0.0002)
not sure whats wrong... – flawr – 2014-10-03T21:36:53.800I tried a few different methods now but all result in about 200 to 300m off in the z coordinate. – flawr – 2014-10-03T21:55:16.627
1PS: Should we count bytes as score? – flawr – 2014-10-03T22:06:15.440
@professorfish actually 4 satellites is enough without prior knowledge of the time. There will only be one consistent solution for time and position together (or put another way, only one time that lets you get a consistent solution for position). This is more-or-less how GPS time transfer works. – hobbs – 2014-10-04T06:54:04.310
@hobbs Also true. I'll add a rule that your solution doesn't need to take time if it doesn't want to – None – 2014-10-04T07:24:33.687
@flawr Yes, score is in bytes – None – 2014-10-04T13:54:24.277