Trilaterate your position
Desmos, 122 bytes
Online use. Copy+paste each equation into an equation box, click "add all" for each box, then click on the point of intersection, then enter in each value as appropriate. each of A
, B
, and C
are the distances for the points (a,b)
, (c,d)
, and (E,f)
, respectively. To get a square root in the value, type sqrt
then the value in the box.
\left(x-a\right)^2+\left(y-b\right)^2=AA
\left(x-c\right)^2+\left(y-d\right)^2=BB
\left(x-E\right)^2+\left(y-f\right)^2=CC
Verify the first test case.
Or you can take a look here:
C, 362 348 345 bytes
Input is given as a sequence of space-separated floats on stdin: x1 y1 d1 x2 y2 d2 x3 y3 d3
. Output is similar on stdout: x y
.
#define F"%f "
#define G float
#define T(x)(b.x*b.x-a.x*a.x)
typedef struct{G a;G b;G c;}C;G f(C a,C b,G*c){G x=b.b-a.b;*c=(T(a)+T(b)-T(c))/x/2;return(a.a-b.a)/x;}main(){C a,b,c;G x,y,z,t,m;scanf(F F F F F F F F F,&a.a,&a.b,&a.c,&b.a,&b.b,&b.c,&c.a,&c.b,&c.c);x=f(a,a.b==b.b?c:b,&y);z=f(b.b==c.b?a:b,c,&t);m=t-y;m/=x-z;printf(F F"\n",m,x*m+y);}
C
is a structure type whose members are an x-coordinate a
, a y-coordinate b
, and a distance (radius) c
. The function f
takes two C
structures and a pointer to a float, and determines the line at which the C
(circles) intersect. The y-intercept of this line is placed into the pointed-to float, and the slope is returned.
The program calls f
on two pairs of circles, then determines the intersection of the produced lines.
APL (Dyalog Unicode) 18.0, 23 bytes
-∘(+/)⍥(×⍨)⌹⍥(2-⌿⊢)¯2×⊢
Try it online!
A tacit infix function that can be called like dists f pts
, where pts
contains three centers' coordinates as a 3-row 2-column matrix, and dists
contains three distances to the respective centers.
Uses 18.0 feature ⍥
. TIO's Dyalog Unicode is not updated yet from 17.1, so TIO link uses Dyalog Extended for demonstration purposes.
How it works
Uses the same method as R.T.'s Python answer, i.e. constructing a linear system of equations and solving it.
The distance equations are necessarily quadratic. Then how did we get linear ones?
Let's consider just two circles, and denote the point we want to find as \$P\$, two circles' centers as \$C, D\$, and their radii as \$r_C, r_D\$. Also, let's use \$A_x, A_y\$ for the \$x\$- and \$y\$-coordinates of a point \$A\$. Then the following equations hold:
$$ (P_x-C_x)^2+(P_y-C_y)^2 =r_C^2 \\ (P_x-D_x)^2+(P_y-D_y)^2 =r_D^2 \\ $$
Then we expand them and subtract the second from the first:
$$ P_x^2-2P_xC_x+C_x^2+P_y^2-2P_yC_y+C_y^2=r_C^2\\ P_x^2-2P_xD_x+D_x^2+P_y^2-2P_yD_y+D_y^2=r_D^2\\ -2P_x(C_x-D_x)+(C_x^2-D_x^2)-2P_y(C_y-D_y)+(C_y^2-D_y^2)=r_C^2-r_D^2\\ -2P_x(C_x-D_x)-2P_y(C_y-D_y)=(r_C^2-C_x^2-C_y^2)-(r_D^2-D_x^2-D_y^2) $$
We've just got one linear equation on \$P_x\$ and \$P_y\$. Since we have three circles given, we can take any two pairs and construct two equations, which then solving the system of equations gives the coordinates we want.
-∘(+/)⍥(×⍨)⌹⍥(2-⌿⊢)¯2×⊢ ⍝ Left: dists, Right: pts
-∘(+/)⍥(×⍨) ⍥(2-⌿⊢) ⍝ Constants part
⍥(×⍨) ⍝ Square each number in both dists and pts
∘(+/) ⍝ Row sums of squared pts
- ⍝ Subtract above from squared dists
⍥(2-⌿⊢) ⍝ Take pairwise difference
⍥(2-⌿⊢)¯2×⊢ ⍝ Coefficients part
¯2×⊢ ⍝ -2 times pts
⍥(2-⌿⊢) ⍝ Take pairwise difference between rows
⌹ ⍝ Solve linear equations