如何将二次贝塞尔曲线代码转换为三次贝塞尔曲线? [英] How to convert quadratic bezier curve code into cubic bezier curve?

查看:431
本文介绍了如何将二次贝塞尔曲线代码转换为三次贝塞尔曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我最近开始进行图形编程,我想计算三次贝塞尔曲线.我在二次贝塞尔曲线上发现了这个绝佳的答案,但我不知道如何将其转换为三次贝塞尔曲线.

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循环更改为:

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( 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 );
}

这篇关于如何将二次贝塞尔曲线代码转换为三次贝塞尔曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆