I've got a follow-up question for the previously asked and answered question here
What I am trying to do now is that when I have a third coordinate I want it to be converted to the closest point on the x line.

This is what I got and it works with small coordinates but as soon as I use large coordinates it goes wrong.
First I use this formula (credits to Unit):
(b1−a1)(x1−b1)+(b2−a2)(x2−b2)
Example:
having
A = 8,4
B = 4,8
C = 0,8
(4-8)(0-4)+(8-4)(8-8) = 16
So afterwards to get the closest point to the x line I do this:
(√16)/2 = 2
If it's a negative number I count the result down on the x-axis and I count the result up on the y-axis and if it's a positive number I do it the other way around so I would get (2,6) as a result which results as 0 in the formula.
This works perfectly for me but when I use real coordinates with 15 decimals it doesn't work right.
This is what I get with real coordinates

C extends too much while I used the point where the red spot is in the formula, and it should be somewhere very close to the red spot.
Sorry the way you go on about is not good
Given points $ A (a_1, a_2) $ and $ B (b_1, b_2) $
and you want to find a point C on the x axis $(c_2=0)$
you get:
$ (b_1 − a_1)(c_1 − b_1) + (b_2 − a_2)(c_2 −b_2) = 0 $
$ (b_1 − a_1)(C_1 − b_1) + (b_2 − a_2)(0 −b_2) =0 $
$ c_1(b_1 − a_1) − b_1(b_1 − a_1) - b_2 (b_2 − a_2) =0 $
$ c_1(b_1 − a_1) = b_1(b_1 − a_1) + b_2 (b_2 − a_2) $
$ c_1(b_1 − a_1) = b_1^2 − b_1a_1 + b_2^2 − b_2a_2 $
$$ c_1 = \frac{b_1^2+b_2^2 -b_1a_1 -b_2a_2}{b_1−a_1} $$
or
if you want to find a point D on the y axis $(d_1=0)$
$ (b_1 − a_1)(d_1 − b_1) + (b_2 − a_2)(d_2 −b_2) = 0 $
$ (b_1 − a_1)(0 − b_1) + (b_2 − a_2)(d_2 −b_2) =0 $
$ (b_1 − a_1) (− b_1) + (b_2 − a_2)(d_2) + (b_2 − a_2)(− b_2) = 0 $
$ -b_1(b_1 − a_1) + d_2(b_2 − a_2) -b_2 (b_2 − a_2) = 0 $
$ d_2(b_2 − a_2) = b_1(b_1 − a_1) +b_2 (b_2 − a_2) $
$ d_2(b_2 − a_2) = b_1^2 − b_1a_1 + b_2^2 − b_2a_2 $
$$ d_2 = \frac{b_1^2 + b_2^2 - b_1a_1 - b_2a_2}{b_2 − a_2} $$