繁体   English   中英

Casteljau c ++ Vector2D花键

[英]Casteljau c++ Vector2D Spline

我确实让deCasteljau运行。 我在我检查的代码中写了注释。

这是deCasteljau的伪代码:

DeCasteljau(anz, P[], t){ 
for(j=anz-2; j>=0; j--)
 for(i=0; i<=j; i++)
  P[i]=(1-t) * P[i] + t * P[i+1];
}

我必须使用Vector2D。

#include <stdlib.h>
#include <GL\glut.h>
#include <iostream>
#include <cmath>
#include "Vector2D.h"

using namespace std;

#define PI 3.14159265

int w = 600;
int h = 600;

int array[][2] = { { 0, 0 }, { 2, 4 }, { 3 ,5 } };


Vector2D p0(0,0);
Vector2D p1(0,0);
Vector2D p2(0,0);

float deCasteljau(float t){

Vector2D x;
Vector2D y;

p0.setXY(array[0][0], array[0][1]);
p1.setXY(array[1][0], array[1][1]);
p2.setXY(array[2][0], array[2][1]);

for (int j=3-2;j>=0;j--)
    for (int i=0; i<=j; i++)
    {
        //how to write this: P[i]=(1-t) * P[i] + t * P[i+1]
    }
return P[0]; //and here to

 }

void display(void) {
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0, 1.0, 0.0);
glBegin(GL_POINTS);

    //how is the code for draw the spline?

glEnd();


glFlush();
}

 void init(void) {
/* select clearing color    */
glClearColor(0.0, 0.0, 0.0, 0.0);

/* initialize viewing values  */
glOrtho(0, w, 0, h, -1, 1);
}

 int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(w + 100, h + 100);
glutInitWindowPosition(100, 0);
glutCreateWindow("Aufgabe7");
    for(int t=0; t<=1;t=t+0.01){
       deCasteljau(t);
    }
init();
glutDisplayFunc(display);
glutMainLoop();

return 0; /* ANSI C requires main to return int. */
}

你可以写这个

//how to write this: P[i]=(1-t) * P[i] + t * P[i+1]

P[i].x= (1-t) * P[i].x + t * P[i+1].x;
P[i].y= (1-t) * P[i].y + t * P[i+1].y;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM