How Impedance triangle is formed?
Vector math.
In a series RL circuit, current I is same through both R and L. It will be in some phase with respect to the supply source V.
Voltage, Current, Impedance can be represented as vectors as they have both magnitude as well as phase.

First you need a reference vector. I disregard the supply and its phase and take voltage drop across R, \$V_R\$ vector as the reference. So I can represent it as a horizontal line.
Then current vector will be in the same line as both are in phase in a resistor.
(\$\vec {V_R}\angle 0,\vec I\angle 0\$)




Since the same current flows through L, the current vector of L is the same as  R. In Inductor, current and voltage have 90 degree phase shift between each other.
(\$\vec {V_L}\angle 90,\vec I\angle 0\$)



The result is the familiar voltage triangle of RL circuit.

Now you can straight forward deduce the impedance vectors.
$$\frac{\vec {V_R}\angle0}{\vec I\angle 0} = R \angle 0$$
$$\frac{\vec {V_L}\angle90}{\vec I\angle 0} = X_R \angle 90$$
Result is the impedance triangle similar to voltage triangle.