Taking any two points (x_1, y_1)(x1,y1) and (x_2, y_2)(x2,y2) on the plane, in general it is possible to form a right angled triangle with the line between these two points forming the hypotenuse. Denote this line by CC for convenience.
One of the other sides (denote this by AA for convenience) is the line joining the point (x_1, y_1)(x1,y1) to the point (x_1, y_2)(x1,y2). This line will be parallel to the y-axis (because the value of xx remains the same, here denoted by x_1x1).
The remaining side (denote this by BB for convenience) is the line joining the point (x_2, y_2)(x2,y2) to the point (x_1, y_2)(x1,y2). This line will be parallel to the x-axis (because the value of yy remains the same, here denoted by y_2y2).
Note that the second points mentioned in the two previous sentences are the same; this is the vertex that encloses the right angle of the right angled triangle.
The length of the side that is parallel with the x-axis may be calculated as (x_2 - x_1)(x2−x1), that is, letting AA now denote the length of the line, A = (x_2 - x_1)A=(x2−x1).
The length of the side that is parallel with the y-axis may be calculated as (y_2 - y_1)(y2−y1), that is, letting BB now denote the length of the line, B = (y_2 - y_1)B=(y2−y1).
Denoting the length of the line joining the two points by CC, it might be noted that CC is the hypotenuse of a right angled triangle with two remaining sides AA and BB.
So, by Pythagoras' theorem
C^2 = A^2 + B^2C2=A2+B2
or (noting that we are only interested in the positive square root in this particular problem),
C = sqrt(A^2 + B^2)C=√A2+B2
So, the length of the line (denoted by CC) joining the points (x_1, y_1)(x1,y1) and (x_2, y_2)(x2,y2) is given by
C = sqrt((x_2 - x_1)^2 + (y_2 - y_1)^2)C=√(x2−x1)2+(y2−y1)2
As it happens, in this particular problem, the value taken by y_1y1 and by y_2y2 is the same in both cases (it happens to be zero) so that (y_2 - y_1) = 0(y2−y1)=0.
That is, the right angled triangle is "degenerate" because one of its sides is of zero length.
Despite that, the general formula for the distance between two points still works.
That is, in this particular case, in which x_1 = -3x1=−3, y_1 = 0y1=0, x_2 = 4x2=4 and y_2 = 0y2=0
C = sqrt((4 - (-3))^2 - (0-0)^2) = sqrt((4 + 3)^2 - 0^2) = sqrt(7^2 - 0) = sqrt(49) = 7C=√(4−(−3))2−(0−0)2=√(4+3)2−02=√72−0=√49=7
(taking the positive square root) as noted in the previous explanation provided by Julia.