資源簡(jiǎn)介
基于qt5.8寫(xiě)的一個(gè)貝塞爾曲線
qt5.8工程源碼
直接打開(kāi)編譯,不是網(wǎng)上轉(zhuǎn)的,是自己寫(xiě)的,里面有注釋
貝塞爾曲線的t系數(shù)是0.5
C++寫(xiě)貝塞爾曲線,可以在任意平臺(tái)編譯,可移植的貝塞爾曲線
貝塞爾曲線例子
Bezier demo
bezier curve writen by qt5.8
qt5.8 project of bezier, you can open the pro file and compile the project directly
it is fully test and reliable.
this bezier curve's t factor is 0.5f
C++ coede of bezier, cross platfor

代碼片段和文件信息
#include?“beziercruve.h“
BezierCruve::BezierCruve(Qobject?*parent)?:?Qobject(parent)
????maxDotQty(0)
????dotQty(0)
????dotInterval(1)
{
????cruveDots.clear();
????dotQty?=?0;
????dotInterval?=?1;
}
void?BezierCruve::bezier_draw_cruve(MY_POINT?*pInPoints)
{
????if?(dotQty?<=?0)?return;//point?qty?invalide;
????if((pInPoints[dotQty].x??pInPoints[0].x-dotInterval)
????????????&&?(pInPoints[dotQty].y??pInPoints[0].y-dotInterval))//如果第一點(diǎn)的xy坐標(biāo)和第n點(diǎn)的不重合,不是一個(gè)點(diǎn)
????{
????????//pDC->SetPixel(pInPoints[0].x?pInPoints[0].y?RGB(255000));//0x0000ff,這里的每一個(gè)點(diǎn)都是貝塞爾曲線,pInPoints[0],每次遞歸之后,拍p[0]會(huì)接近最后一點(diǎn)p[dotQty]
????????cruveDots.append(pInPoints[0]);
????????return;
????}
????MY_POINT?*p1;
????p1?=?new?MY_POINT[dotQty+1];
????int?i?j;
????p1[0]?=?pInPoints[0];
????for(i=1;?i<=dotQty;?i++)//第1點(diǎn)到第n點(diǎn),可以遍歷n-1次
????{
????????for(j=0;?j<=dotQty-i;j++)//從第0點(diǎn)到n-i,意識(shí)是每畫(huà)一點(diǎn)之后,j可以遍歷少一點(diǎn)
????????{
????????????//pDC->MoveTo(pInPoints[j].x?pInPoints[j].y);
????????????//pDC->LineTo(pInPoints[j+1].x?pInPoints[j+1].y);
????????????pInPoints[j].x?=?(pInPoints[j].x?+?pInPoints[j+1].x)/2.0f;//取得x之間的中點(diǎn)
????????????pInPoints[j].y?=?(pInPoints[j].y?+?pInPoints[j+1].y)/2.0f;//取得每相鄰的y點(diǎn)之間的中點(diǎn)
????????????//pDC->SetPixel(pInPoints[i].x?pInPoints[i].y?RGB(25500));
????????????//pDC->Rectangle(pInPoints[j].x?-?2?pInPoints[j].y?-2?pInPoints[j].x?+?2?pInPoints[j].y?+?2);
????????????//Sleep(2000);
????????}//執(zhí)行完畢,pInPoints[j]變成兩個(gè)線之間的中點(diǎn)
????????p1[i]?=?pInPoints[0];
????}//每次i和j一起,歷遍到?jīng)]點(diǎn)連線的最后一個(gè)中點(diǎn)
????bezier_draw_cruve(pInPoints);
????bezier_draw_cruve(p1);
????delete?p1;
????//emit?cruveDots;//發(fā)送信號(hào)和數(shù)據(jù)不可以在遞歸里面發(fā)生,否則多次發(fā)送
}
void?BezierCruve::bezier_set_point_interval(qint32?pix)
{
????dotInterval?=?pix;
}
void?BezierCruve::bezier_set_dot_qty(qint32?dot)
{
????dotQty?=?dot;
}
void?BezierCruve::bezier_set_max_dot_qty(qint32?maxDot)
{
????maxDotQty?=?maxDot;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-09-06?09:00??BezierCruve\
?????文件????????2361??2017-09-05?21:04??BezierCruve\beziercruve.cpp
?????文件?????????662??2017-09-03?17:07??BezierCruve\beziercruve.h
?????文件????????1132??2017-09-03?17:05??BezierCruve\BezierCruve.pro
?????文件???????23835??2017-09-05?22:17??BezierCruve\BezierCruve.pro.user
?????文件?????????171??2017-09-05?20:57??BezierCruve\commondata.h
?????文件?????????885??2017-09-05?21:33??BezierCruve\main.cpp
?????文件????????3437??2017-09-05?22:16??BezierCruve\mainwindow.cpp
?????文件?????????931??2017-09-05?22:09??BezierCruve\mainwindow.h
?????文件????????1177??2017-09-05?21:42??BezierCruve\mainwindow.ui
?????文件????????2293??2017-09-05?22:08??BezierCruve\renderarea.cpp
?????文件????????2173??2017-09-03?21:53??BezierCruve\renderarea.cpp.fD7112
?????文件????????1175??2017-09-05?22:11??BezierCruve\renderarea.h
評(píng)論
共有 條評(píng)論