user3144125
user3144125

Reputation: 59

C# 3D plot with panel on high performance

I have to plot some math functions in 3d with a panel in C#. What is the best method to do an high-performance drawing? Now I calculate the coordinates of the points and use the DrawPolygon method for draw some polygons of different form and colors, but the plot is flickering and slow. Should I delay the update of panel when the function is complete?

for (int i = 0; i < nIteration-1; i++)
{
     for (int j = 0; j < nIteration-1; j++)
     {
          // Polygon points 
          draw[0] = points[i + 1][j];
          draw[1] = points[i][j];
          draw[2] = points[i][j + 1];
          draw[3] = points[i+1][j+1]; 

          // Color gradint
          brush = new LinearGradientBrush(rect,
                  color[i][j],
                  color[i + 1][j + 1], LinearGradientMode.Vertical);

          // Polygon coloured
          graph.SmoothingMode = SmoothingMode.None;
          graph.FillPolygon(brush, draw);

          // Polygon black border
          graph.SmoothingMode = SmoothingMode.AntiAlias;
          graph.DrawPolygon(pen, draw);
    }
}

Upvotes: 1

Views: 440

Answers (1)

jgallant
jgallant

Reputation: 11273

You are going to want to look into Double Buffering.

http://msdn.microsoft.com/en-us/library/system.drawing.bufferedgraphics%28v=vs.110%29.aspx

Upvotes: 1

Related Questions