Derivation of Lorentz transformation

Denote the event when the origins coincide $O$.

Suppose an event $A$ occurs at coordinate $x,t$ in frame $S$. We can break down $x$ into $$ x = vt + r = vt + \frac{x'}{\gamma} $$ $$ x' = \gamma(x-vt) $$ where $r$ is the observed length of the ruler and $x'$ is the proper length.

We can swap the frames and get $$ x = \gamma(x'+vt'). $$ Substituting, $$\begin{align*} x &= \gamma(\gamma(x-vt)+vt') \\ (1-\gamma^2)x + \gamma^2 vt &= \gamma vt' \\ t' &= \frac{(1-\gamma^2)x + \gamma^2 vt}{\gamma v} \\ \end{align*}$$ We simplify $(1-\gamma^2)$ by $$ 1-\gamma^2 = 1 - \frac{1}{1-v^2/c^2} = -\frac{v^2/c^2}{1-v^2/c^2} = -\frac{\gamma^2 v^2}{c^2} $$ so $$ t' = \gamma\Big(t - \frac{vx}{c^2}\Big). $$

Perpendicular lengths do not change so $y'=y$ and $z'=z$.