1

我有一个带有固定点和随机生成的用户位置的网格。

每个点和用户的距离从轴 0.0 的起点开始测量。我想将每个用户与最近的固定点相关联。我计算了两个距离向量,每个用户的最小值都指向最近的固定点。

但我坚持寻找一种工作方式,以便每个固定点和相关用户在情节上都有相同的东西,pe相同的颜色和颜色区域。

所以我的问题是二维的:

  1. 首先是设法将每个用户与其最近的固定点相关联
  2. 如何为结果着色。

谢谢你。

4

2 回答 2

1

For the point searching I would use dsearchn for this kind of thing. You can use it with or without delaunay triangulation depending on the ratio of users to fixed sites. I tend to use it the quick and easy way, which in your case would be:

indices_of_closest_fixed_points = dsearchn(fixed_points, user_points)

As for the colors I would suggest you define a color map using something like

mymap = lines(n) 

where n is the number of fixed points you have. You can then use scatter to plot the points with specific colors and sizes. Perhaps something like this to get you started:

x = user_points(1,:); 
y = user_points(2,:);
S = []; % point sizes, left empty for now
C = mymap(indices_of_closest_fixed_points,:); %colors

scatter(x,y,S,C);
于 2012-10-24T21:27:33.117 回答
0

user要找到最近的点,只需计算每个点与完整点集之间的欧几里得距离fixed。那么最短距离的索引也将是该fixed点的索引。

dist = calc_dist(fixedPts, aSingleUserPt)
[~, idx] = min(dist); 

要解决颜色问题,您需要创建一个从fixed点索引到唯一颜色的颜色图。然后,当您plot指向用户时,您会将绘图的颜色设置为等于在idx

注意欧几里得距离很容易计算:

euc_dist = sqrt( (x1 - x2)^2 + (y1 - y2)^2 );

File Exchange 上有一些功能可以让您快速计算。

于 2012-10-24T21:09:29.973 回答