为什么我只获得一次 20 个新积分? [英] Why im getting 20 new points only once?

查看:17
本文介绍了为什么我只获得一次 20 个新积分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先是想法和目标:我有一个方法可以获取两个点和一些点来创建并返回一个点列表,其中包含要在点之间创建的新点数.

First the idea the goal: I have a method that get two points and a number of points to create and return me a List of points with the new number of points to create in between the points.

第一个问题是比如第一次pt1是181172,pt4是180171但在结果中我看到里面有 20 分,但第一个是:

First problem is that for example in the first time pt1 is 181,172 and pt4 is 180,171 But in the result i see 20 points inside but the first one is:

180,171 而最后一个是 181,172我需要保持它原来的样子.给定的两个点应该首先在相同的索引上:181,172 然后最后在索引 02 180,171

180,171 and the last one is 181,172 And i need to keep it on the same way it was. The given two points should be on the same indexs first: 181,172 and then in the end on index 02 180,171

第二个问题是它只做一次就返回20分一次.这是我使用该方法的方式:

The second problem is that its doing it only once return 20 points once only. This is how im using the method:

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;

云现在只包含 20 个点,但在原始云中有 37 个点,并且 DistributePoints 方法应该每次从云中取出两个点,并在这两个点之间添加新的 20 个点.

clouds now contain only 20 points but in the original clouds was with 37 points and and the method DistributePoints should take each time two points from clouds and add between the two points new 20 points.

方法:

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;
        }

但由于某种原因,它在我不想要的图片框点上的某处添加了更多的 20 点.

But for some reason its adding painting more 20 points somewhere on the pictureBox points i didnt want.

我得到的结果是:我用黑色标记了我不需要的点:

The result im getting is: I marked with black the points i dont need:

(点击查看大图)

我该如何解决?

我认为问题就在这里:

for (int i = 0; i < clouds.Count - 1; i += 2)
            {
                extendedPoints.AddRange(DistributePoints(new PointF(clouds[i].X, clouds[i].Y), new PointF(clouds[i + 1].X, clouds[i + 1].Y), 20));
            }
            clouds = extendedPoints;

如果云包含 37 个点(索引)并且我将其发送到该方法 20 次,最终云应包含 740 个点(索引).但由于某种原因,云只包含 360 个点(索引).

If clouds contain 37 points(indexs) and i send it to the method 20 times in the end clouds should contain 740 points(indexs). But for some reason clouds contain only 360 points(indexs).

37 * 20 = 740那为什么云到底只有360点呢?

37 * 20 = 740 Then why clouds in the end is containing only 360 points ?

所以我有这个问题,最终云只包含 360 个点,我还有另一个问题,它在我不希望的某个地方绘制了 20 个点.奇怪.

So i have this problem that in the end clouds contain only 360 points and i have the other problem that its drawing 20 points in some place i didnt want it to be. strange.

编辑**

我认为这段代码部分有问题:

Something i think is wrong in this code part:

for (int i = 0; i < clouds.Count - 1; i += 1)
            {
                extendedPoints.AddRange(DistributePoints(new PointF(clouds[i].X, clouds[i].Y), new PointF(clouds[i + 1].X, clouds[i + 1].Y), 20));
            }
            clouds = extendedPoints;

如果我在 FOR += 1 中做,那么最终云以 720 点结束,但随后我看到在其他一些位置绘制了两组 20 点作为线条格式.

If im doing in the FOR += 1 then in the end clouds end with 720 points but then i see two sets of 20 points drawed on some other locations as a line format.

如果我在 FOR += 2 中做,那么最终云以 360 点结束,但随后我看到一组 20 点绘制在其他位置作为线条格式.

If im doing in the FOR += 2 then in the end clouds end with 360 points but then i see one set of 20 points drawed on some other location as a line format.

如果我在 FOR += 3 中做,那么最终云以 240 点结束,但这次没有在其他位置绘制的 20 点.但是 240 分是不正确的,我认为它应该以 740 或 777 分在云端结束.

If im doing in the FOR += 3 then in the end clouds end with 240 points only but this time without those 20 points drawed on other location. But 240 points is not right i think it should end with 740 or 777 points in clouds.

编辑**

ja72 这是我现在用你的代码得到的:

ja72 this is what im getting now with your code:

这就是我在绘制事件中绘制点的方式:

This is how im drawing the points in the paint event:

public static void Paint(Graphics e, double currentFactor, float kilometers)
        {
            float distance = kilometers / (float)1.09;//289617486; // One pixel distance is 1.09 kilometer.
            Pen p;
            p = new Pen(Brushes.Green);
            if (points == null)
            {
                return;
            }


            foreach (PointF pt in clouds)
            {
                e.FillEllipse(Brushes.Red, (pt.X - distance) * (float)currentFactor, pt.Y * (float)currentFactor, 4f, 4f);
            }

在这种情况下:km = 0.0 和 currentFactor = 1.0也许这里的油漆事件是错误的,但我不这么认为.

In this case: kilometers = 0.0 and currentFactor = 1.0 Maybe something here with the paint event is wrong but i dont think so.

推荐答案

据我所知,这就是您想要的:

From what I can best tell this is what you want:

public static List<PointF> DistributePoints(PointF pt_start, PointF pt_end, int number_of_points)
{
    List<PointF> result=new List<PointF>();
    float x_start=pt_start.X, x_end=pt_end.X;
    float y_start=pt_start.Y, y_end=pt_end.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_start+(x_end-x_start)*scale, y=y_start+(y_end-y_start)*scale;
        result.Add(new PointF(x, y));
    }
    return result;
}

static void Main(string[] args)
{
    List<PointF> clouds=new List<PointF>();
    List<PointF> extended=new List<PointF>();
    // add N points to clouds
    // there are N-1 intervals
    for (int i=1; i<clouds.Count; i++)
    {
        extended.AddRange( DistributePoints( clouds[i-1], clouds[i], 20));
    }
    // extended now has (N-1)*20 points
}

这篇关于为什么我只获得一次 20 个新积分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆