Tia*_*iax 5 c# triangulation cartesian-coordinates
网格http://i44.tinypic.com/1qo5mp.png
(角落中的小点是节点,红点是被跟踪的人)
坐标:
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
Run Code Online (Sandbox Code Playgroud)
获得信号强度的方法:
(只需要相对于其他节点的信号强度,它似乎达到了.或者我错了吗?)
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);
}
Run Code Online (Sandbox Code Playgroud)
信号强度:
Node Signal Strength
1 -108
2 -372
3 -391
4 -529
Run Code Online (Sandbox Code Playgroud)
获取人的坐标的方法:
(s1,s2,s3,s4是上面的信号强度)
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) };
}
Run Code Online (Sandbox Code Playgroud)
人员职位:
x: 290
y: 296
Run Code Online (Sandbox Code Playgroud)
正如你所看到的那样,我在数学方面并不擅长,而且"人的位置"也是如此.并不重要,但如果这个人处于网格中间,它就会起作用.
我正在假设如果每个节点具有相同的信号强度,那么该人就在网格的中间.
有人可以帮我这个吗?谷歌搜索和抨击我的头对着桌子一段时间了.
实际上,您应该只需要 3 个节点即可完成此操作。
这里的基本概念是每个信号强度告诉您与节点的距离。在没有其他信息的情况下,您可以从每个节点构建一个半径等于信号强度的半圆。当然,这个人必须躺在半圆的某个地方。
因此,通过一个节点,我们构建了一个半圆,这会导致该人可能存在的位置有无数个点。
对于两个节点,我们发现两个半圆可能在多达两个位置相交。事实上,如果人不在精确的中心,两个相对的节点将在窗口边界内的两个不同点处相交,但如果人在屏幕的中心,则仅在一个点(中心)相交。
通过引入第三个节点,保证第三个半圆与前两个半圆在它们相交的两个点之一处相交。
这三个节点相交的位置就是人居住的地方。
正如 the_lotus 所说,这是一个三边测量问题。
这是您需要的函数(您甚至可以s4从参数列表中剪切):
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) };
}
Run Code Online (Sandbox Code Playgroud)