資源簡介
基于qt5.8寫的一個貝塞爾曲線
qt5.8工程源碼
直接打開編譯,不是網上轉的,是自己寫的,里面有注釋
貝塞爾曲線的t系數是0.5
C++寫貝塞爾曲線,可以在任意平臺編譯,可移植的貝塞爾曲線
貝塞爾曲線例子
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))//如果第一點的xy坐標和第n點的不重合,不是一個點
????{
????????//pDC->SetPixel(pInPoints[0].x?pInPoints[0].y?RGB(255000));//0x0000ff,這里的每一個點都是貝塞爾曲線,pInPoints[0],每次遞歸之后,拍p[0]會接近最后一點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點到第n點,可以遍歷n-1次
????{
????????for(j=0;?j<=dotQty-i;j++)//從第0點到n-i,意識是每畫一點之后,j可以遍歷少一點
????????{
????????????//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之間的中點
????????????pInPoints[j].y?=?(pInPoints[j].y?+?pInPoints[j+1].y)/2.0f;//取得每相鄰的y點之間的中點
????????????//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);
????????}//執行完畢,pInPoints[j]變成兩個線之間的中點
????????p1[i]?=?pInPoints[0];
????}//每次i和j一起,歷遍到沒點連線的最后一個中點
????bezier_draw_cruve(pInPoints);
????bezier_draw_cruve(p1);
????delete?p1;
????//emit?cruveDots;//發送信號和數據不可以在遞歸里面發生,否則多次發送
}
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;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????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
評論
共有 條評論