Here is the result of that construction:

There's one sign error (in the definition of x_center).

Are you familiar with the fact that AB*BP = TP^2? That's what t is.

x_center has two solutions actually, as I am implementing fortunes algorithm the solution which is closer to AB line is the ideal solution.

thank you for the answer

Yes, when this method is applicable, there are two solutions. The ABS(k) bit isn't necessary - when there are two solutions, just add and subtract t, to get the two x_center values. (That is, if you want the 2 solutions, of course).

Two examples with 2 solutions each:

An example with 1 solution (when the two points are on the same horizontal level).

(When there is only one solution, the method used in this post doesn't work - an alternative is needed).

An example with 0 solutions:

An example with an infinite number of solutions!