Deriving formula for perspective correct interpolation

I am trying to derive the formula for perspective correct texture interpolation on my own while implementing my own software rasterizer (projecting an arbitrarily rotated triangle in camera space on the projection plane and rasterize its texture). Sure, the solution is that one can interpolate the inverse of z in the projection plane (or screen space). However, given the assumption that I do not know that yet, all I came up with so far is the following:

My first step was to formulate the problem (maybe my problem statement is the problem?) and visualize it. Then I tried to find some relations between the variables.

What I am now looking for is some hint / observation that leads to right direction (not the solution).

• It may help if you try to express things in terms of deltas, like $\Delta x = (x_t - x_1)$ and $\Delta x' = (x'_s - x'_1)$. Also try to bring in the slope of z with respect to x, $\Delta z / \Delta x$ (which is a constant all along the triangle). Sep 17 at 19:54

The diagram is on the right track but all the x's and z's can be confusing to follow. I suggest just giving positions on the diagram plain old points. For example naming points on the triangle p1 and p2, then naming points on the image plain q1 and q2, ect. That makes it a easier/more intuitive to follow the math which would then refer to the individual components. Like $$q_x$$ and $$p_z$$ for arbitrary points on either plane.