繪製漸變的貝塞爾曲線

2021-08-21 03:15:25 字數 1256 閱讀 5728

前面介紹了使用qt中的api繪製貝塞爾曲線,使用qt的api繪製貝塞爾曲線可參見繪製貝塞爾曲線,本章介紹一下使用線段連線的方式繪製一條漸變的貝塞爾曲線。效果如下圖所示:

二階貝塞爾曲線的公式如下: b(

t)=p

0(1−

t)3+

3p1t

(1−t

)2+3

p2t2

(1−t

)+p3

t3,t

∈[0,

1]b (t

)=p0

(1−t

)3+3

p1t(

1−t)

2+3p

2t2(

1−t)

+p3t

3,t∈

[0,1

]p0p

0為起始點的座標,p3

p

3為終點的座標,p1

p

1和p2

p

2為控制點的座標。t在0-1之間取值,b(t)為計算的曲線座標點。

完整的程式**如下,本例子中取100個樣點進行繪製:

標頭檔案

#include 

class beziercurve : public qwidget

;

原始檔

#include "beziercurve.h"

#include

#include

#include

#include

beziercurve::beziercurve(qwidget *parent)

:qwidget(parent)

beziercurve::~beziercurve()

void beziercurve::paintevent(qpaintevent *event)

void beziercurve::drawbeziercurve(qpainter* painter, qpointf startpos, qpointf c1, qpointf c2, qpointf endpos)

painter->restore();

}qcolor beziercurve::getgradientcolor(int index)

繪製貝塞爾Bezier曲線

trainingtools.cpp 定義控制台應用程式的入口點。include include include include include include using namespace std const int ww max mark count 40 最大40個控制點 int mark c...

OPENGL繪製貝塞爾曲線

最終效果圖 通過3個點形成一條貝塞爾曲線 1.滑鼠問題 在使用滑鼠獲取座標的時候,要知道滑鼠獲取的座標和螢幕座標是不同的 opengl使用右手座標 從左到右,x遞增 從下到上,y遞增 從遠到近,z遞增 而滑鼠是從左到右增x,同時從上到下也是增y 所以在求 y 的時候,用 螢幕大小 y 來獲取 2.繪...

繪製貝塞爾曲線通用方法

計算三次貝塞爾曲線,後面n n 3 計算時,都是將點分成一組一組的三次貝塞爾曲線 skpoint calcthreebezier wm5 vector2d ptw1,wm5 vector2d ptw2,wm5 vector2d ptw3 繪製貝塞爾曲線函式 void drawbezier vecto...