本文介绍了如何将二次贝塞尔曲线代码转换为三次贝塞尔曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我最近开始进行图形编程,我想计算三次贝塞尔曲线.我在二次贝塞尔曲线上发现了这个绝佳的答案,但我不知道如何将其转换为三次贝塞尔曲线.
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 ); }更多推荐
如何将二次贝塞尔曲线代码转换为三次贝塞尔曲线?
发布评论