Step-by-step explanation:
as you can see, the distance between 2 points can always be seen as the Hypotenuse or baseline of a right-angled triangle created by the differences of the x and y coordinates of both points.
the drawn triangle is nothing else than that.
to calculate the length of a side in such a triangle we need to use Pythagoras :
c² = a² + b²
c is the Hypotenuse of baseline of the triangle and is opposite of the 90 degree angle.
a and b are the legs of the triangle "enclosing" the 90 degree angle.
so, we have
AB² = AC² + BC²
AC and BC we know : the coordinate differences in x and y directions.
AC = (4, 5) to (4, 2). as the x coordinates are the same, the difference is just the difference in the y coordinates : 5-2 = 3.
BC = (1, 2) to (4, 2). as the y coordinates are the same, the difference is just the difference in the x coordinates : 5-1 = 3.
AB² = 3² + 3² = 9 + 9 = 18
AB = sqrt(18)
FYI : sqrt(18) = sqrt(9×2) = 3×sqrt(2)