【发布时间】:2013-12-31 04:05:03
【问题描述】:
这是ja72的方法:
public static List<PointF> DistributePoints(PointF pt1, PointF pt4, int number_of_points)
{
List<PointF> result = new List<PointF>();
float x_min = Math.Min(pt1.X, pt4.X), x_max = Math.Max(pt1.X, pt4.X);
float y_min = Math.Min(pt1.Y, pt4.Y), y_max = Math.Max(pt1.Y, pt4.Y);
if (number_of_points < 2) throw new ArgumentException("Need Two Points At Least");
for (int i = 0; i < number_of_points; i++)
{
float scale = (float)i / (number_of_points - 1);
float x = x_min + (x_max - x_min) * scale, y = y_min + (y_max - y_min) * scale;
result.Add(new PointF(x, y));
}
return result;
}
这就是我使用它的方式:
for (int i = 0; i < clouds.Count - 1; i += 2)
{
extendedPoints = DistributePoints(new PointF(clouds[i].X, clouds[i].Y), new PointF(clouds[i + 1].X, clouds[i + 1].Y), 20);
}
clouds = extendedPoints;
return clouds;
clouds 是 PointF 列表 扩展点也是 PointF 列表。
在这种情况下,现在在云中我有 37 个索引(点)。
例如,假设在索引 0 的云中,我有:x = 150 y = 200 和索引 1:x = 160 y = 250 所以我使用你的 ja72 方法,现在扩展点包含 20 个点:
extendedPoints 的格式应该是这样的:
index 0 : x = 150 y = 200
index 1 : x = 152 y = 210
index 2 : x = 155 y = 220
.
.
.
.
.
index 21 : x = 160 y = 250
现在这是一个迭代。 下一个应该从原始 List 索引 2 和索引 3 中获取云并将它们发送到您的方法并返回另外 20 个点。
现在extendedPoints 应该是这样的:
index 0 : x = 150 y = 200
index 1 : x = 152 y = 210
index 2 : x = 155 y = 220
.
.
.
.
.
index 21 : x = 160 y = 250
index 22 : x = 165 y = 255 ( this index 21 is the original index 2 of clouds )
index 23 : x = 166 y = 260
.
.
.
.
.
index 42 : x = 200 y = 300 ( this is the index 42 should be the original index 3 of clouds )
换句话说,我需要保持云的所有点坐标与它们在原始云列表中的顺序相同,并在每两个点之间添加新的 20 个点。
最后,云的所有原始点都应该按照与之前相同的顺序排列,但在每两个点之间添加新的 20 个点。
问题是你的方法只在云上迭代一次而不是 37 次。 最后,每次混合点时都应该添加 pt1 和 pt4,因为它们的顺序相同。
【问题讨论】:
-
点应该有
x和y坐标。您正在尝试创建只有x或只有y的点。你的意图是什么? -
考虑将方法重命名为
DistributePoints,因为它沿pt1和pt4之间的线分布N点。 -
另外,将
double作为for()循环变量也不是一个好主意。 -
无需转换为
double,然后转换为float,只需将所有数学运算保留在float。