You should actually only need 3 nodes to do this.
The basic concept here is that each signal strength tells you distance from the node. With no other information, you can construct a semicircle from each node with radius equal to the signal strength. Certainly, the person must lie somewhere on the semicircle.
So, with one node, we construct a semicircle and it results in an infinite number of points where the person could be.
With two nodes, we find that the two semicircles may intersect in as many as two locations. In fact, the two opposite nodes will intersect at two distinct points within the window's boundaries if the person is not in the exact center, but will intersect at only one point (the center) if the person is at the center of the screen.
With the introduction of the third node, the third semicircle is guaranteed to intersect the first two semicircles at one of the two points at which they intersect.
The location where these three nodes intersect is where the person resides.
As stated by the_lotus, this is a Trilateration problem.
Here's the function, you need (you can even cut s4
from the parameter list):
public int[] GetPositionInGrid(int s1, int s2, int s3, int s4)
{
var px = ((s1 * s1)
- (s2 * s2)
+ (this.node2.Left * this.node2.Left))
/ ((double)(2 * this.node2.Left));
var py = ((s1 * s1)
- (s3 * s3)
+ (this.node3.Left * this.node3.Left)
+ (this.node3.Top * this.node3.Top))
/ (2 * this.node3.Top)
- (this.node3.Left / (double)this.node3.Top)
* px;
return new int[] { Convert.ToInt32(px), Convert.ToInt32(py) };
}