Parallax scaling in 2d I have a stack of images, trees, buildings, a mountain and a sky background. I need to transform the $x$ and $y$ coordinates of each layer in the stack to produce parallax, giving the illusion of depth.
I was using a simple Pythagorus equation to determine how much to scale down the parallax movement as a function of distance.
However I don't think this is correct. Is there an equation, perhaps a weak perspective solution that would give me a transform scaling based on distance on $z$?
 A: One possibility is to choose a vanishing point in the view and then use cross-ratios.  
For simplicity, I’ll assume that all of the images in the stack have the same dimensions, $w\times h$, and that the view coordinate system is right-handed with the origin at lower left. For the scene, we compute the cross-ratio $(\mathbf 0,\mathbf 1;\mathbf z,\mathbf\infty)$ for a line perpendicular to the image stack. It is $${\begin{vmatrix}0&1\\z&1\end{vmatrix} \begin{vmatrix}1&1\\1&0\end{vmatrix} \over \begin{vmatrix}0&1\\1&0\end{vmatrix} \begin{vmatrix}1&1\\z&1\end{vmatrix}} = {z\over z-1}.$$ Now choose a vanishing point $\mathbf v=(v_x,v_y)$ in the image. Points on the line segment from the origin to the vanishing point then have coordinates $t\mathbf v$ for $t\in[0,1]$. You will also need to choose a point along this line segment that corresponds to a depth of $z=1$, say $f\mathbf v$. The corresponding cross-ratio on this line segment is then $${t(1-f)\over t-f}.$$ Equating these two cross-ratios, we have $$t={fz\over f(z-1)+1}.$$ The other three corners of the transformed image rectangle are then $(1-t)(w,0)+t\mathbf v$, $(1-t)(0,h)+t\mathbf v$ and $(1-t)(w,h)+t\mathbf v$. From these points we can see that the image is uniformly scaled by $1-t = {1-f\over f(z-1)+1}$. Varying $f$ will change the apparent focal distance.  
Here is an example of the rectangles that result for integral depths from $0$ to $4$ with $f=1/4$:

