(The small dots in the corners are the nodes and the red dot is the person being tracked)
Coordinates:
Node X Y Position
1 0 0 Top left
2 450 0 Top right
3 0 450 Bottom left
4 450 450 Bottom right
Person X Y
Red dot 84 68
Method to get signal strength:
(Just need the signal strength relative to other nodes, which it seem to achieve. Or am I wrong here?)
public int GetSignalStrength(OvalShape node)
{
int xd = node.Left - this.person.Left;
int yd = node.Top - this.person.Top;
var signalStrength = Math.Sqrt((xd * xd) + (yd * yd));
return Convert.ToInt32(-signalStrength);
}
Signal strengths:
Node Signal Strength
1 -108
2 -372
3 -391
4 -529
Method to get coordinates of person:
(s1, s2, s3, s4 are the signal strengths above)
public int[] GetPositionInGrid(int s1, int s2, int s3, int s4)
{
var tx1 = this.node1.Left;
var ty1 = this.node1.Top;
var tx2 = this.node2.Left;
var ty2 = this.node2.Top;
var tx3 = this.node3.Left;
var ty3 = this.node3.Top;
var tx4 = this.node4.Left;
var ty4 = this.node4.Top;
double w1 = ((double)s1) / ((double)(s1 + s2 + s3 + s4));
double w2 = ((double)s2) / ((double)(s1 + s2 + s3 + s4));
double w3 = ((double)s3) / ((double)(s1 + s2 + s3 + s4));
double w4 = ((double)s4) / ((double)(s1 + s2 + s3 + s4));
var px = ((tx1 * w1) + (tx2 * w2) + (tx3 * w3) + (tx4 * w4)) / (w1 + w2 + w3 + w4);
var py = ((ty1 * w1) + (ty2 * w2) + (ty3 * w3) + (ty4 * w4)) / (w1 + w2 + w3 + w4);
return new int[] { Convert.ToInt32(px), Convert.ToInt32(py) };
}
Person position:
x: 290
y: 296
As you can see I'm not that good at math and the "Person position" is way off. Not that it matters but it works if the person is in the middle of the grid.
I'm working with the assumption that if every node has the same signal strength the person is in the middle of the grid.
Can someone please help me with this? Been googling and bashing my head against the table for awhile now.