改进平滑曲线
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "smoothcurve.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
QPainterPath SmoothCurve::createSmoothCurve(const QVector<QPointF> &points)
|
||||
{
|
||||
@@ -20,6 +21,29 @@ QPainterPath SmoothCurve::createSmoothCurve(const QVector<QPointF> &points)
|
||||
return path;
|
||||
}
|
||||
|
||||
QPainterPath SmoothCurve::createSmoothCurve2(const QVector<QPointF> &points)
|
||||
{
|
||||
//采用Qt原生方法不做任何处理
|
||||
int count = points.count();
|
||||
if (count == 0) {
|
||||
return QPainterPath();
|
||||
}
|
||||
|
||||
QPainterPath path(points.at(0));
|
||||
for (int i = 0; i < count - 1; ++i) {
|
||||
//控制点的 x 坐标为 sp 与 ep 的 x 坐标和的一半
|
||||
//第一个控制点 c1 的 y 坐标为起始点 sp 的 y 坐标
|
||||
//第二个控制点 c2 的 y 坐标为结束点 ep 的 y 坐标
|
||||
QPointF sp = points.at(i);
|
||||
QPointF ep = points.at(i + 1);
|
||||
QPointF c1 = QPointF((sp.x() + ep.x()) / 2, sp.y());
|
||||
QPointF c2 = QPointF((sp.x() + ep.x()) / 2, ep.y());
|
||||
path.cubicTo(c1, c2, ep);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void SmoothCurve::calculateFirstControlPoints(double *&result, const double *rhs, int n)
|
||||
{
|
||||
result = new double[n];
|
||||
@@ -41,8 +65,8 @@ void SmoothCurve::calculateFirstControlPoints(double *&result, const double *rhs
|
||||
}
|
||||
|
||||
void SmoothCurve::calculateControlPoints(const QVector<QPointF> &datas,
|
||||
QVector<QPointF> *firstControlPoints,
|
||||
QVector<QPointF> *secondControlPoints)
|
||||
QVector<QPointF> *firstControlPoints,
|
||||
QVector<QPointF> *secondControlPoints)
|
||||
{
|
||||
int n = datas.size() - 1;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user