I'm quite new in C#, please give some advice. In a Windows Form app I have several points on my canvas, linked with lines (e.g. a polygon). I want to calculate every middle point of the lines and link the dots with a button click so I can smooth the polygon.
I wrote the following code but it doesn't put the midpoints onto the screen, and I have no idea why. Where I did I make a mistake?
P is the original list with the points. NewPoints is my new list with the new points.
private void button1_Click(object sender, EventArgs e)
{
NewPoints.Add(P[0]);
for (int i = 0; i < P.Count; i++)
{
NewPoints.Add(new Point( (P[i + 1].X+P[i].X)/2, (P[i + 1].Y + P[i].Y) / 2));
}
NewPoints.Add(P[P.Count - 1]);
P.Clear();
for (int j = 0; j < NewPoints.Count; j++)
P.Add(NewPoints[j]);
NewPoints.Clear();
canvas.Refresh();
}