QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_spline_polynomial.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *
9 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_SPLINE_POLYNOMIAL_H
28#define QWT_SPLINE_POLYNOMIAL_H
29
30#include "qwt_global.h"
31
32#include <qpoint.h>
33#include <qmetatype.h>
34
47class QWT_EXPORT QwtSplinePolynomial
48{
49public:
50 QwtSplinePolynomial(double c3 = 0.0, double c2 = 0.0, double c1 = 0.0);
51
52 bool operator==(const QwtSplinePolynomial&) const;
53 bool operator!=(const QwtSplinePolynomial&) const;
54
55 double valueAt(double x) const;
56 double slopeAt(double x) const;
57 double curvatureAt(double x) const;
58
59 static QwtSplinePolynomial fromSlopes(const QPointF& p1, double m1, const QPointF& p2, double m2);
60
61 static QwtSplinePolynomial fromSlopes(double x, double y, double m1, double m2);
62
63 static QwtSplinePolynomial fromCurvatures(const QPointF& p1, double cv1, const QPointF& p2, double cv2);
64
65 static QwtSplinePolynomial fromCurvatures(double dx, double dy, double cv1, double cv2);
66
67public:
69 double c3;
70
72 double c2;
73
75 double c1;
76};
77
78Q_DECLARE_TYPEINFO(QwtSplinePolynomial, Q_MOVABLE_TYPE);
79Q_DECLARE_METATYPE(QwtSplinePolynomial)
80
81
88inline QwtSplinePolynomial::QwtSplinePolynomial(double a3, double a2, double a1) : c3(a3), c2(a2), c1(a1)
89{
90}
91
99{
100 return (c3 == other.c3) && (c2 == other.c2) && (c1 == other.c1);
101}
102
110{
111 return (!(*this == other));
112}
113
120inline double QwtSplinePolynomial::valueAt(double x) const
121{
122 return (((c3 * x) + c2) * x + c1) * x;
123}
124
131inline double QwtSplinePolynomial::slopeAt(double x) const
132{
133 return (3.0 * c3 * x + 2.0 * c2) * x + c1;
134}
135
142inline double QwtSplinePolynomial::curvatureAt(double x) const
143{
144 return 6.0 * c3 * x + 2.0 * c2;
145}
146
159inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes(const QPointF& p1, double m1, const QPointF& p2, double m2)
160{
161 return fromSlopes(p2.x() - p1.x(), p2.y() - p1.y(), m1, m2);
162}
163
175inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes(double dx, double dy, double m1, double m2)
176{
177 const double c2 = (3.0 * dy / dx - 2 * m1 - m2) / dx;
178 const double c3 = ((m2 - m1) / dx - 2.0 * c2) / (3.0 * dx);
179
180 return QwtSplinePolynomial(c3, c2, m1);
181}
182
195inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures(const QPointF& p1, double cv1, const QPointF& p2, double cv2)
196{
197 return fromCurvatures(p2.x() - p1.x(), p2.y() - p1.y(), cv1, cv2);
198}
199
211inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures(double dx, double dy, double cv1, double cv2)
212{
213 const double c3 = (cv2 - cv1) / (6.0 * dx);
214 const double c2 = 0.5 * cv1;
215 const double c1 = dy / dx - (c3 * dx + c2) * dx;
216
217 return QwtSplinePolynomial(c3, c2, c1);
218}
219
220#ifndef QT_NO_DEBUG_STREAM
221
222class QDebug;
223QWT_EXPORT QDebug operator<<(QDebug, const QwtSplinePolynomial&);
224
225#endif
226
227#endif
A cubic polynomial without constant term
Definition qwt_spline_polynomial.h:48
double slopeAt(double x) const
Calculate the value of the first derivate of a polynomial for a given x
Definition qwt_spline_polynomial.h:131
static QwtSplinePolynomial fromSlopes(const QPointF &p1, double m1, const QPointF &p2, double m2)
Find the coefficients for the polynomial including 2 points with specific values for the 1st derivate...
Definition qwt_spline_polynomial.h:159
double valueAt(double x) const
Calculate the value of a polynomial for a given x
Definition qwt_spline_polynomial.h:120
bool operator==(const QwtSplinePolynomial &) const
Compare two polynomials for equality
Definition qwt_spline_polynomial.h:98
static QwtSplinePolynomial fromCurvatures(const QPointF &p1, double cv1, const QPointF &p2, double cv2)
Find the coefficients for the polynomial including 2 points with specific values for the 2nd derivate...
Definition qwt_spline_polynomial.h:195
bool operator!=(const QwtSplinePolynomial &) const
Compare two polynomials for inequality
Definition qwt_spline_polynomial.h:109
double c1
coefficient of the linear summand
Definition qwt_spline_polynomial.h:75
double c3
coefficient of the cubic summand
Definition qwt_spline_polynomial.h:69
double c2
coefficient of the quadratic summand
Definition qwt_spline_polynomial.h:72
double curvatureAt(double x) const
Calculate the value of the second derivate of a polynomial for a given x
Definition qwt_spline_polynomial.h:142