I have a trilateration-related problem that I'm unsure how to solve mathematically. I can see a solution is possible through geometry, but I'm unsure how to solve the resulting equations.
Given three 2D points, find where to put a new point on the same plane. You know the exact distances from the new point to each existing point.
By drawing a picture, it is clear that this is attainable:
In this image, $P_1,P_2,P_3$ are the known points, and $P_4$ is the point we want to find coordinates for. The red lines denote known distances.
Given only two points, we can find 2 candidate positions (where the circles intersect), while the third given point limits us to our solution.
Using the properties of circles, I have come up with 3 equations and 2 unknowns. Let $P_i=[x_i,y_i]^T$ and $r_i=|P_i-P_4|$ for $i\in\{1,2,3,4\}$. Then my set of equations, expanded, is $$r_1^2 = (x_4 - x_1)^2 + (y_4 - y_1)^2\\ r_2^2 = (x_4 - x_2)^2 + (y_4 - y_2)^2\\ r_3^2 = (x_4 - x_3)^2 + (y_4 - y_3)^2$$ How can I calculate $x_4$ and $y_4$?
I FOUND THE ANSWER I WAS LOOKING FOR
(I'd answer my own question, but since it's closed as a duplicate all I can do is post it here)
So I was hoping to find a way to express this as a linear least-squares ($Ax=b$) type problem. I mentioned that in the comments, but not in this OP. Regardless, the link from @dxiv in the comments below helped me get to this solutions. Also worth mentioning, the question this is a duplicate of reaches the same conclusion (as it obviously should). It just stops short of the $Ax=b$ form.
In short, the approach is to combine the 3 quadratic equations to get 2 linear ones.
Given
$$\text{(1) } r_1^2 = (x_4 - x_1)^2 + (y_4 - y_1)^2\\ \text{(2) }r_2^2 = (x_4 - x_2)^2 + (y_4 - y_2)^2\\ \text{(3) }r_3^2 = (x_4 - x_3)^2 + (y_4 - y_3)^2$$
we first expand each to
$r_i^2 = \hat{x}^2 + \hat{y}^2 - 2\hat{x}x_i - 2\hat{y}y_i + x_i^2 + y_i^2$
Then we subtract (2) from (1) and (3) from (1):
$$\text{(1)-(2) }2\hat{x}(x_2 - x_1) + 2\hat{y}(y_2 - y_1) + (x_1^2 - x_2^2) + (y_1^2 - y_2^2) - (r_1^2 - r_2^2) = 0\\ \text{(1)-(3) }2\hat{x}(x_3 - x_1) + 2\hat{y}(y_3 - y_1) + (x_1^2 - x_3^2) + (y_1^2 - y_3^2) - (r_1^2 - r_3^2) = 0$$
This is now able to be expressed as an least-squares problem, particularly as an $Ax=0$ (i.e. nullspace) problem if the distances $r_i$ are precise.
$\left[ \begin{matrix} 2(x_2 - x_1) & 2(y_2 - y_1) & (x_1^2 - x_2^2) + (y_1^2 - y_2^2) - (r_1^2 - r_2^2) \\ 2(x_3 - x_1) & 2(y_3 - y_1) & (x_1^2 - x_3^2) + (y_1^2 - y_3^2) - (r_1^2 - r_3^2) \end{matrix} \right] \left[ \begin{matrix} \hat{x} \\ \hat{y} \\ 1 \\ \end{matrix} \right] \left[ \begin{matrix} 0 \\ 0 \end{matrix} \right] $
Thus, in short, the solution for $\left[ \begin{matrix} \hat{x} \\ \hat{y} \end{matrix} \right]$ is found in the nullspace of the $A$ matrix.
If the distances $r_i$ have some uncertainty, this can be expressed as a linear least-squares minimization problem which is easily solvable using SVD.
By drawing a picture, it is clear that this is attainable
Pictures are not proofs. The $3$ distances are not independent.while the third given point limits us to our solution
Solve the first two equations for $x_4, y_4$ first, then use the third equation to eliminate unwanted solutions. – dxiv Oct 01 '16 at 03:52