This is the method im doing inside the calculation:
private static List<PointF> ExtendPoints(PointF pt1, PointF pt4, int numberOfPoints) { if (!extendedPoints.Contains(pt1)) { extendedPoints.Add(pt1); } for (double d = 1; d <= numberOfPoints; d++) { double a = (Math.Max(pt1.X, pt4.X) - Math.Min(pt1.X, pt4.X)) * d / (double)(numberOfPoints + 1 ) + Math.Min(pt1.X, pt4.X); double b = (Math.Max(pt1.Y, pt4.Y) - Math.Min(pt1.Y, pt4.Y)) * d / (double)(numberOfPoints + 1 ) + Math.Min(pt1.Y, pt4.Y); var pt2 = new PointF((float)a, (float)b); extendedPoints.Add(pt2); } extendedPoints.Add(pt4); return extendedPoints; }
This method ExtendPoints get two points pt1 and pt4 and return a List of points according to the numberOfPoints.
For example if the variable numberOfPoints is 2 then the formula in the method ExtendPoints should be:
(n - 1) * m + n
n = the length of the original List of points
m = numberOfPoints
For example lets say the length of the original list of points is 37.
And numberOfPoints is now 2.
So the calculation should be: (37 - 1) * 2 + 37 = 109
This formula is the base the core of the method.
Even if numberOfPoints is set to 500 and the List of points length is 40 same formula calculation:
(500 - 1) * 40 + 500
Then i created a new method that using this method:
public static void AddPoints() { points = Load(); for (int i = 1; i < points.Count; i++) { if (i == 18) { break; } extendedPoints = ExtendPoints(points[i - 1], points[i], 2); } }
When i make points = Load(); then points now contain in this case 37 points inside.
For example in index 0 i see: X = 120 Y = 121
And this is how i call it from form1:
CloudEnteringAlert.AddPoints();
And then last thing is im drawing the points after padding them using ExtendPoints method in pictureBox:
foreach (PointF pt in extendedPoints) { e.FillEllipse(Brushes.Red, pt.X, pt.Y, 3f, 3f); }
Now when im using the ExtendPoints method im getting in then after looping over all the points List im getting a new List called extendedPoints and i see the right number of points i should get according to the formula.
If the List of points is 37 and numberOfPoints is 2 so in the end extendedPoints length is realy 109 points.
The problem is when im drawing the points in extendedPoints i see some strange drawings.
First this is an image when im drawing the original List: points.
Then this is an image after im using the ExtendPoints method ot pad the points.
Padding i mean using the method and formula the method get two points each time and return a new list with 2 new points.
If the method ExtendPoints get from the List points index 0 and index 1(thats two points) then the method will return a new List with 4 points: pt1 then two new points and then pt4.
The next itertion the method ExtendPoints will get from the List points index 1 and index 2.
This time the method will retun a List of 3 points: the tw new points and pt4.
Next itertion: it will get index 2 and index 3 and will return another List of 3 points: pt1 two new points and pt4.
And so on.
But this is what im getting when im using the ExtendPoints method:
You can see that in the top the points are filled(padded) but them for some reason just after the top its getting more and more like points and that it didnt fill/pad between each two points. The original points left alone and the padded points are in other locations. And it should be like it is in the top in the beginning.
I think something wrong with the Math and calculation i did in the ExtendPoints method.