Reputation: 1
I would like to make a mapping application that maps indoor places such as malls. I need to be able to calculate the latitude and longitude of any point on a particular map (i.e. know the latitude and longitude of a particular store). I know that the maps are probably rotated and not aligned with true north, so I would first need to supply the information about a few points to sort of "calibrate" so that the orientation of the map is known, if you get what I mean.
My map will be formatted like a grid/coordinate system. I will supply the latitude and longitude of three specific points on a map. After supplying this information, how can I calculate the latitude and longitude of any other point on the map? For example, I have a map, and I tell my program the latitude and longitude data of (0, 0), (5, 5), and (10, 12). I then input (3, 5) and the program should tell me the latitude and longitude of that point.
Is this possible to do? How would I go about writing the algorithm for this? Also, is it possible to do this with the user supplying the positions of only two points to the program? Thanks!
Upvotes: 0
Views: 2168
Reputation: 96109
Assuming your mall is small enough that you can consider Lat and Long to be linear ie same as X and Y then it's simply a matter of applying scaling and rotation transformation matrices.
If your maths is a little weak you might want to try this simple introduction
You also need to be able to convert between lat/long and metres (or feet or pixels). Latitude (how far north/south) is easy - because a circle drawn through the poles is the same length, so a degree of latitude is always the same number of metres (to your accuracy). Longitude is trickier, because circles drawn around the earth get smaller as you go further north - see Expressing_latitude_and_longitude_as_linear_units
Alternately if you know the Lat/Long of known points (eg the corners) you can just scale from degrees into metres/feet/pixels directly. Remembering that the N-S scale is different from the E-W scale.
Upvotes: 1
Reputation: 57388
It is possible, and you would only need the position of two points. If the area is small enough, you don't need to worry about the plane being slanted or the Earth being round.
Suppose that you have two points X1,Y1 and X2,Y2 in map-coordinates (pixels would do, if you have a scanned map. Or millimeters. Or whatever).
Of these two points you also know the coordinates in, say, UTM, and let these be x1,y1 and x2,y2.
From this information you can derive the rotation and zooming required to change from UTM to map and vice versa.
At that point, given any other point of which you know the map coordinates X3,Y3, its UTM coordinates may be calculated.
Supposing that the X and Y axes have the same orientation of UTM reference (for this you would need managing the rotation, and that's more complicated - a little trigonometry is involved),
x2-x1 = Zx * (X2-X1)
x3-x1 = Zx * (X3-X1)
and therefore
Zx = (X2-X1)/(x2-x1)
x3 = x1 + Zx * (X3-X1)
and finally
x3 = x1 + (X3-X1)*[ (X2-X1)/(x2-x1) ]
(the part in square brackets won't change after you take the position of your two points - it will be a sort of calibration constant).
Same goes for y3 and Y3. Note that the Y axis might have opposite sign in respect to y.
For REALLY small areas you might just convert latitude and longitude into straight arbitrary units considering one degree equal to 60 minutes, one minute equal to 60 seconds, and one second equal to 1000 milliseconds. Then convert from latitude (or longitude) to milliseconds. The number you'll get will have very little significance -- you don't know what a "millisecond" is -- but once you calculate, say, x3 in milliseconds, you will be able to get it back to longitude and forget the milliseconds; and that longitude will be useable and approximately correct. If you don't stray far from your two points; if you don't take them too distant. A big mall is okay, a city... not so okay.
The algorithm is very basic and I expect to be soon lynched by an angry mob of cartographers and mathematicians (and I will have deserved it), but for SMALL areas allowing to consider the Earth as locally flat, it just might work.
Upvotes: 0