Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include<stdio.h>
- #include<string>
- #include"glut.h"
- const int n = 5;
- const int k = 4;
- GLfloat pp[n][2] = {
- -0.4, -0.4,
- -0.2, 0.4,
- 0, -0.4,
- 0.2, 0.4,
- 0.4, -0.4
- };
- GLfloat x[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; //period
- //GLfloat x[] = { -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 5, 5, 5 }; //открытый В сплайн
- void init() {
- glClearColor(1, 1, 1, 1);
- }
- double N(int i, int k, double t) {
- if (k == 1) {
- if (t < x[i] || t > x[i + 1])
- return 0;
- return 1;
- }
- double a = 0, b = 0;
- if ((x[i + k - 1] - x[i]) != 0) a = (t - x[i])*N(i, k - 1, t) / (x[i + k - 1] - x[i]);
- if ((x[i + k] - x[i + 1]) != 0) b = (x[i + k] - t)*N(i + 1, k - 1, t) / (x[i + k] - x[i + 1]);
- return a + b;
- }
- void Display() {
- //glColor3f(0, 0, 0);
- glBegin(GL_POINTS);
- for (double i = 3; i <= 5; i += 0.001) { // (k-1) < < (n+1)
- double x = 0;
- double y = 0;
- for (int j = 1; j <= n; ++j) {
- double n = N(j, k, i);
- x += pp[j - 1][0] * n;
- y += pp[j - 1][1] * n;
- glColor3f(0.01*j, j % 7 * 0.1, j % 2);
- //glVertex2d(0.3*(i - 3), 0.3*n - 0.8); //внизу кривые
- }
- glColor3f(0, 0, 0);
- glVertex2d(x - 0.3, y); // splain
- }
- for (int i = 0; i < n; ++i) {
- glVertex2d(pp[i][0] - 0.3, pp[i][1]); // to4ki
- }
- glEnd();
- glutSwapBuffers();
- glutPostRedisplay();
- }
- int main() {
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowSize(480, 480);
- glutInitWindowPosition(100, 100);
- glutCreateWindow(" ");
- init();
- glutDisplayFunc(Display);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement