简体   繁体   English

如何将二次贝塞尔曲线代码转换为三次贝塞尔曲线?

[英]How to convert quadratic bezier curve code into cubic bezier curve?

So I've recently picked up graphics programming and I wanted to compute a cubic Bézier curve. 因此,我最近开始进行图形编程,并且想计算三次贝塞尔曲线。 I found this excellent answer on quadratic Bézier but I don't know how to convert this to a cubic Bézier curve. 我在二次贝塞尔曲线上找到了一个很好的答案 ,但我不知道如何将其转换为三次贝塞尔曲线。

For cubic Bézier curve, as you see in the link you shared, the green lines are obtained from the same procedure as the quadratic one. 对于立方贝塞尔曲线,如您在共享链接中所见,绿线是通过与二次曲线相同的过程获得的。 the differences are: you have two green lines, and then you need to calculate a blue line based on them. 区别在于:您有两条绿线,然后需要根据它们计算一条蓝线。 So the for loop changes as: 因此, for循环更改为:

for( float i = 0 ; i < 1 ; i += 0.01 )
{
    // The Green Lines
    xa = getPt( x1 , x2 , i );
    ya = getPt( y1 , y2 , i );
    xb = getPt( x2 , x3 , i );
    yb = getPt( y2 , y3 , i );
    xc = getPt( x3 , x4 , i );
    yc = getPt( y3 , y4 , i );

    // The Blue Line
    xm = getPt( xa , xb , i );
    ym = getPt( ya , yb , i );
    xn = getPt( xb , xc , i );
    yn = getPt( yb , yc , i );

    // The Black Dot
    x = getPt( xm , xn , i );
    y = getPt( ym , yn , i );

    drawPixel( x , y , COLOR_RED );
}

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

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