2017-05-05 11 views
0

私は2次ベジェ曲線を描いています。なぜそれがそのように動作しているのかわかりません。曲線に影響を与える別の制御点があるように見えますが、制御点は3つしかなく、数式は2次曲線のみです。 http://imgur.com/a/wOWSeベジェ曲線に何が問題なのですか?

とコード:

Point Bezier::evaluate(float t) 
{ 
    // [x,y]=(1–t)^2*2P0+2(1–t)t*P1+t^2*P2 

    Point P; 
    P.x = (1 - t)*(1 - t)*points[0].x + 
      2*(1 - t)*(1 - t)*t*points[1].x + 
      t*t*points[2].x; 

    P.y = (1 - t)*(1 - t)*points[0].y + 
      2*(1 - t)*(1 - t)*t*points[1].y + 
      t*t*points[2].y; 

    return P; 
} 

void Bezier::drawCurve() 
{ 
    glColor3d(red, green, blue); 
    Point lastPoint = points[0]; 

    for (float t = 0.0; t <= 1.0; t += 0.01) 
    { 
     Point currentPoint = evaluate(t); 
     drawLine(lastPoint.x, lastPoint.y, currentPoint.x, currentPoint.y); 
     lastPoint = currentPoint; 
    } 
} 

void Bezier::drawHandles() 
{ 
    glColor3d(red, green, blue); 

    for (int i = 0; i < 3; i++) 
    { 
     drawCircle(points[i].x, points[i].y, points[i].radius); 
    } 
} 

ヘッダーを任意の助けを事前に

class Point 
{ 
    public: 
     float x; 
     float y; 
     float radius = 5; 
}; 

class Bezier 
{ 
    public: 
     Bezier(float startX, float startY, float endX, float endY, float red, float green, float blue); 
     Point evaluate(float time); 
     void drawCurve(); 
     void drawHandles(); 

     Point points[3]; 

     float red; 
     float green; 
     float blue; 
}; 

おかげでここ

は、それがやっていることのいくつかの画像です!

答えて

6

使用している数式は、あなたが第二項に余分(1-t)を持って

P.x = (1 - t)*(1 - t)*points[0].x + 
     2*(1 - t)*t*points[1].x + 
     t*t*points[2].x; 

P.y = (1 - t)*(1 - t)*points[0].y + 
     2*(1 - t)*t*points[1].y + 
     t*t*points[2].y; 

間違っています。

+0

agh私はそれが数式にあると思って、それを3回以上読んでから、確かに投稿してください。どういうわけか、それは逃げました。ありがとう! – Grav

+0

心配はいりません!これはいつも起こります。 –

関連する問題