TITLE: Finding the position where a picture was taken
QUESTION [10 upvotes]: Assuming I have a photo where a few significant points are visible, and I can point them out on a map. How many points would I have to identify, in order to find the precise position? Would I also find the altitude?
A small example:
Points:
point   coordinates               elevation    pixel in photo (of 4032x3024)
red      -13.156197,-72.546324    2494.0 m     1229x1201 px
blue     -13.161653,-72.545699    2450.0 m     1050x1938 px
pink     -13.158724,-72.540743    1994.0 m     2156x2436 px
yellow   -13.166027,-72.542900    2394.0 m     1604x2545 px
green    -13.163450,-72.544715    2456.0 m     1208x2165 px

picture with annotated points:

map with points:

REPLY [2 votes]: I calculate that the camera was at approximately
$$\text{coordinates }(-13.1611, -72.5427),\ \text{elevation } 2515.16$$
This comes from a problem in 4 unknowns:  3 positions for the Cartesian coordinates $(P_i,P_j,P_k)$ of the camera, and 1 factor $r$ which relates camera angles to picture distances.
Specifically, I assume that if the camera is at $P$, then two points $X$ and $Y$ are separated in the picture by a distance in pixels of
$${XY}_3 := r\, \tan(\angle XPY).$$ (The subscript 3 indicates that this is calculated from the 3-dimensional cordinates.) By the identity $\tan^2=-1+\sec^2$ we get
$${XY}_3^2 = r^2\left(-1+\frac{1}{\cos^2(\angle XPY)}\right)$$
$${XY}_3^2 = r^2\left(-1+\frac{|P-X|^2|P-Y|^2}{((P-X)\cdot(P-Y))^2}\right)$$
We compare this with the actual 2-dimensional distance in pixels, which we call ${XY}_2$. We should have ${XY}_3={XY}_2$ for all pairs of points in the picture, and we can approximate this by minimizing
$$\sum_{X,Y} ({XY}_3^2-{XY}_2^2)^2$$
starting from a guess that $P$ is the average of the points on the map, and $r$ is roughly the pixel-size of the picture.
Here is Mathematica code for the calculation, including a conversion between latitude-longitude-altitude and a Cartesian coordinate system based at the center of the earth.
red    = {-13.156197, -72.546324, 2494, 1229, 1201}
blue   = {-13.161653, -72.545699, 2450, 1050, 1938}
pink   = {-13.158724, -72.540743, 1994, 2156, 2436}
yellow = {-13.166027, -72.542900, 2394, 1604, 2545}
green  = {-13.163450, -72.544715, 2456, 1208, 2165}
data   = {red, blue, pink, yellow, green}

earthrad    = 2 10^7/Pi
phi[x_]    := x[[1]] Pi/180
theta[x_]  := x[[2]] Pi/180
meters[x_] := {Cos[theta[x]] Cos[phi[x]],
               Sin[theta[x]] Cos[phi[x]], 
               Sin[phi[x]]} (earthrad + x[[3]])

p               = {pi, pj, pk}
Norm2[x_]      := x.x
dist3d[x_, y_] := r^2 (-1 + Norm2[p - x] Norm2[p - y]/((p - x).(p - y))^2)
delta[x_, y_]  := (dist3d[meters[x], meters[y]] - Norm2[(x - y)[[4 ;; 5]]])^2

deltas = Sum[delta[data[[i]], data[[j]]], {i, 1, 4}, {j, i + 1, 5}];
avg    = meters[Mean[data]]
sol    = FindMinimum[deltas, {pi, avg[[1]]}, {pj, avg[[2]]}, {pk, avg[[3]]}, {r, 1000}]

tosphere[{x_, y_, z_}] := {ArcSin[z/Sqrt[x^2 + y^2 + z^2]] 180/Pi,
                           ArcTan[y/x] 180/Pi,
                           Sqrt[x^2 + y^2 + z^2] - earthrad}
tosphere[p /. sol[[2]]]