Let $x,$y
and $p,$q
be the given coordinates of A and B, furthermore call $d
the known distance between A and C and $d0
the known distance between A and B. By doing a little math you get the following formulae (here I'm directly implementing it in PHP):
$m = $x + ($q - $y) * $d / $d0;
$n = $y - ($p - $x) * $d / $d0;
There is also a second solution:
$m = $x - ($q - $y) * $d / $d0;
$n = $y + ($p - $x) * $d / $d0;
EDIT: Here is how I got the equations: I rotated the vector AB, which has the coordinates ($p - $x, $q - $y)
, by 90 degrees to obtain ($q - $y, -($p - $x))
and (-($q - $y), $p - $x)
(depending whether clockwise or counter-clockwise) and then got the vector AC by scaling it with $d / $d0
(the ratio of their lengths). Now I just translated the vector by ($x, $y)
to get ($m, $n)
.
Maybe this can be implemented more elegantly by using a vector class in PHP or even a whole library, but I think for this simple calculation it is much easier to implement it "by hand".