Let #A = (1, 1)#, #B = (2, 3)# and #P = (x, y)#
The gradient or slope #m# of a line passing through two points #(x_1, y_1)# and #(x_2, y_2)# is given by the formula:
#m = (y_2 - y_1) / (x_2 - x_1)#
So #m_(AP) = (y-1) / (x - 1)# and #m_(PB) = (y - 3) / (x - 2)#
Assume for now that #x != 1#, #x != 2# so that these slopes are both defined.
If a line has slope #m#, then any line perpendicular to it will have slope #-1/m#. So the product of the slopes of two perpendicular lines is #m * (-1/m) = -1#.
#P# lies on the circle with diameter #AB# if and only if #AP# and #PB# are perpendicular. That is, if and only if #m_(AP) m_(PB) = -1#
#-1 = m_(AP) * m_(PB) = (y-1) / (x - 1) * (y - 3) / (x - 2) = ((y-1)(y-3))/((x-1)(x-2))#
Multiply both ends by #(x-1)(x-2)# to get:
#(y-1)(y-3) = -(x-1)(x-2)#
Add #(x-1)(x-2)# to both sides to get:
#(x-1)(x-2) + (y-1)(y-3) = 0#
What about the cases where #x = 1# or #x = 3# ?
This final equation is the equation of a circle that passes through the points #(1, 1)#, #(2, 3)#, #(1, 3)# and #(2, 1)#. The fact that the gradients of #AP# or #PB# at those points is not defined just means that our construction is not applicable at those points.