For more info on Euler Sequences, notation and convention see the generic entry on Euler angle sequences. \\
R 312 ( ϕ , θ , ψ ) = R 2 ( ψ ) R 1 ( θ ) R 3 ( ϕ ) {\displaystyle R_{312}(\phi ,\theta ,\psi )=R_{2}(\psi )R_{1}(\theta )R_{3}(\phi )} \\
The rotation matrices are
R 2 ( ψ ) = [ c ψ 0 − s ψ 0 1 0 s ψ 0 c ψ ] {\displaystyle R_{2}(\psi )=\left[{\begin{matrix}c_{\psi }&0&-s_{\psi }\\0&1&0\\s_{\psi }&0&c_{\psi }\end{matrix}}\right]}
R 1 ( θ ) = [ 1 0 0 0 c θ s θ 0 − s θ c θ ] {\displaystyle R_{1}(\theta )=\left[{\begin{matrix}1&0&0\\0&c_{\theta }&s_{\theta }\\0&-s_{\theta }&c_{\theta }\end{matrix}}\right]}
R 3 ( ϕ ) = [ c ϕ s ϕ 0 − s ϕ c ϕ 0 0 0 1 ] {\displaystyle R_{3}(\phi )=\left[{\begin{matrix}c_{\phi }&s_{\phi }&0\\-s_{\phi }&c_{\phi }&0\\0&0&1\end{matrix}}\right]}
Carrying out the multiplication from right to left \\
R 1 ( θ ) R 3 ( ϕ ) = [ 1 0 0 0 c θ s θ 0 − s θ c θ ] [ c ϕ s ϕ 0 − s ϕ c ϕ 0 0 0 1 ] = [ c ϕ s ϕ 0 − s ϕ c θ c θ c ϕ s θ s θ s ϕ − s θ c ϕ c θ ] {\displaystyle R_{1}(\theta )R_{3}(\phi )=\left[{\begin{matrix}1&0&0\\0&c_{\theta }&s_{\theta }\\0&-s_{\theta }&c_{\theta }\end{matrix}}\right]\left[{\begin{matrix}c_{\phi }&s_{\phi }&0\\-s_{\phi }&c_{\phi }&0\\0&0&1\end{matrix}}\right]=\left[{\begin{matrix}c_{\phi }&s_{\phi }&0\\-s_{\phi }c_{\theta }&c_{\theta }c_{\phi }&s_{\theta }\\s_{\theta }s_{\phi }&-s_{\theta }c_{\phi }&c_{\theta }\end{matrix}}\right]} \\
Finaly leaving us with the Euler 312 sequence \\
R 2 ( ψ ) R 1 ( θ ) R 3 ( ϕ ) = [ c ψ c ϕ − s ψ s θ s ϕ c ψ s ϕ + s ψ s θ c ϕ − s ψ c θ − s ϕ c θ c θ c ϕ s θ s ψ c ϕ + c ψ s θ s ϕ s ψ s ϕ − c ψ s θ c ϕ c ψ c θ ] {\displaystyle R_{2}(\psi )R_{1}(\theta )R_{3}(\phi )=\left[{\begin{matrix}c_{\psi }c_{\phi }-s_{\psi }s_{\theta }s_{\phi }&c_{\psi }s_{\phi }+s_{\psi }s_{\theta }c_{\phi }&-s_{\psi }c_{\theta }\\-s_{\phi }c_{\theta }&c_{\theta }c_{\phi }&s_{\theta }\\s_{\psi }c_{\phi }+c_{\psi }s_{\theta }s_{\phi }&s_{\psi }s_{\phi }-c_{\psi }s_{\theta }c_{\phi }&c_{\psi }c_{\theta }\end{matrix}}\right]}