public void sort() { Points u = vertex[vertex.Count() - 1].second; double max = 0; for (int k = 0; k < vertex.Count(); k++) { if (max < vertex[k].second.x) { max = vertex[k].second.x; u = vertex[k].second; } } bool inv = true; while (inv) { inv = false; for (int i = 1; i < vertex.Count; i++) { int j = i - 1; if (vertex[j].first > vertex[i].first) { Lagrange tmp = vertex[j]; vertex[j] = vertex[i]; vertex[i] = tmp; inv = true; } } } vertex[vertex.Count - 1].second = u; for (int i = 1; i < vertex.Count; i++) { vertex[i - 1].second = vertex[i].first; } calc(); }
public void calc_koef_all(Lagrange prev) { this.h = second.x - first.x; double dif = (second.y - first.y) / h; double beta = 2 * prev.a * first.x + prev.b; this.a = dif / h - beta / h; this.b = beta - 2 * a * first.x; this.c = first.y - beta * first.x + a * first.x * first.x; }
public void add_point(Points a, Points b, bool type, Lagrange prev) { if (a > b) { this.second = a; this.first = b; } else { this.second = b; this.first = a; } if (type) { calc_koef(); } else { calc_koef_all(prev); } }
public void add_point(Points a) { if (vertex.Count() == 0) { if (flag) { vertex.Add(new Lagrange(prev, a)); flag = false; } else { prev = a; flag = true; } } else { Lagrange b = new Lagrange(); b.add_point(vertex[vertex.Count() - 1].second, a, false, vertex[vertex.Count() - 1]); vertex.Add(b); } }
public void Draw(int w) { List <double> ax = new List <double>(); List <double> ay = new List <double>(); List <double> der_y = new List <double>(); List <double> der_x = new List <double>(); if (vertex.Count > 0) { prev1 = vertex[0]; } for (double i = 0; i < w; i += 0.1) { if (get_func((double)i)) { ay.Add(this.func_value); ax.Add((double)i); } } if (vertex.Count > 0) { double y = 0, y1 = 0, y0 = 0; foreach (Lagrange a in vertex) { int steps = 1000; double h = (a.second.x - a.first.x) / steps; double x = a.first.x; y1 = a.get_derivative(x); for (int i = 0; i < steps; i++) { x += h; y = -y1 + y0 + a.get_derivative(x); der_y.Add(y); der_x.Add(x); } y0 = y; } } only_vertex = new double[vertex.Count * 2 + 2]; for (int i = 0; i < vertex.Count * 2; i += 2) { only_vertex[i] = vertex[i / 2].first.x; only_vertex[i + 1] = vertex[i / 2].first.y; } if (vertex.Count != 0) { only_vertex[vertex.Count * 2] = vertex[vertex.Count - 1].second.x; only_vertex[vertex.Count * 2 + 1] = vertex[vertex.Count - 1].second.y; } else { if (flag) { only_vertex[0] = prev.x; only_vertex[1] = prev.y; } } func_spline_value = new double[ay.Count * 2]; integral_spline_value = new double[der_x.Count * 2]; for (int i = 0; i < der_x.Count * 2; i += 2) { integral_spline_value[i] = der_x[i / 2]; integral_spline_value[i + 1] = der_y[i / 2]; } for (int i = 0; i < ay.Count * 2; i += 2) { func_spline_value[i] = ax[i / 2]; func_spline_value[i + 1] = ay[i / 2]; } gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY); gl.VertexPointer(2, 0, func_spline_value); { gl.LineWidth(1); gl.Enable(OpenGL.GL_LINE_STIPPLE); gl.DrawArrays(OpenGL.GL_LINE_STRIP, 0, ay.Count); gl.Disable(OpenGL.GL_LINE_STIPPLE); } gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY); if (flag_dif) { gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY); gl.VertexPointer(2, 0, integral_spline_value); { gl.LineWidth(1); gl.Enable(OpenGL.GL_LINE_STIPPLE); gl.DrawArrays(OpenGL.GL_LINE_STRIP, 0, der_y.Count); gl.Disable(OpenGL.GL_LINE_STIPPLE); } gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY); } }