/// <summary> /// Draw the user input control points and natural spline. /// </summary> private void DrawInteractive(Graphics g) { // Generate natural spline using the control points. if (controlPoints.Count >= 3) { GameObject points = new NaturalSpline(controlPoints); points.Render(g); } // Draw the control points. foreach (Vector3D point in controlPoints) { g.FillEllipse(brush, (int)point.X - 4, (int)point.Y - 4, 8, 8); } }
/// <summary> /// Draw the original NACA airfoil along with the approximate natural spline. /// </summary> private void DrawAirfoil(Graphics g) { // Label the x and y axes. g.DrawString("Y", new Font("Arial", 10), System.Drawing.Brushes.Blue, new Point(0, 0)); g.DrawString("X", new Font("Arial", 10), System.Drawing.Brushes.Blue, new Point(800, 200)); // Draw th x and y axes. g.DrawLine(System.Drawing.Pens.Red, 0, 200, 800, 200); g.DrawLine(System.Drawing.Pens.Red, 0, 0, 0, 400); if (initialized == false) { return; } // Draw the original NACA airfoil. xl1 = 0; yl1 = 200; xu1 = 0; yu1 = 200; yc1 = 200; xc1 = 0; for (i = 0; i <= 100; i++) { xl2 = (int)(800 * xl[i]); yl2 = 200 - (int)(800 * yl[i]); g.DrawLine(System.Drawing.Pens.Red, xl1, yl1, xl2, yl2); xl1 = xl2; yl1 = yl2; xu2 = (int)(800 * xu[i]); yu2 = 200 - (int)(800 * yu[i]); g.DrawLine(System.Drawing.Pens.Red, xu1, yu1, xu2, yu2); xu1 = xu2; yu1 = yu2; xc2 = 8 * i; yc2 = 200 - (int)(800 * yc[i]); g.DrawLine(System.Drawing.Pens.Blue, xc1, yc1, xc2, yc2); xc1 = xc2; yc1 = yc2; } // Specify sample points for the natural spline. int u0 = 100; int u1 = 70; int u2 = 45; int u3 = 20; int u4 = 6; int u5 = 2; int u6 = 0; int l1 = 2; int l2 = 6; int l3 = 25; int l4 = 60; int l5 = 80; int l6 = 100; // Index the points from the original. List <Vector3D> airfoil = new List <Vector3D> { new Vector3D((800 * xu[u0]), 200 - (800 * yu[u0]), 0), new Vector3D((800 * xu[u1]), 200 - (800 * yu[u1]), 0), new Vector3D((800 * xu[u2]), 200 - (800 * yu[u2]), 0), new Vector3D((800 * xu[u3]), 200 - (800 * yu[u3]), 0), new Vector3D((800 * xu[u4]), 200 - (800 * yu[u4]), 0), new Vector3D((800 * xu[u5]), 200 - (800 * yu[u5]), 0), new Vector3D((800 * xu[u6]), 200 - (800 * yu[u6]), 0), new Vector3D((800 * xl[l1]), 200 - (800 * yl[l1]), 0), new Vector3D((800 * xl[l2]), 200 - (800 * yl[l2]), 0), new Vector3D((800 * xl[l3]), 200 - (800 * yl[l3]), 0), new Vector3D((800 * xl[l4]), 200 - (800 * yl[l4]), 0), new Vector3D((800 * xl[l5]), 200 - (800 * yl[l5]), 0), new Vector3D((800 * xl[l6]), 200 - (800 * yl[l6]), 0), }; List <Vector3D> camber = new List <Vector3D> { new Vector3D(8 * 0, 200 - (800 * yc[0]), 0), new Vector3D(8 * 20, 200 - (800 * yc[20]), 0), new Vector3D(8 * 60, 200 - (800 * yc[60]), 0), new Vector3D(8 * 100, 200 - (800 * yc[100]), 0), }; // Generate the natural splines. GameObject airfoilSpline = new NaturalSpline(airfoil); GameObject camberSpline = new NaturalSpline(camber); // Draw the natural splines. airfoilSpline.Render(g); camberSpline.Render(g); // Draw the control points. foreach (Vector3D point in airfoil) { g.FillEllipse(brush, (int)point.X - 4, (int)point.Y - 4, 8, 8); } }