QWT 7.0.1
Loading...
Searching...
No Matches
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{
49 public:
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(
60 const QPointF& p1, double m1,
61 const QPointF& p2, double m2 );
62
63 static QwtSplinePolynomial fromSlopes(
64 double x, double y, double m1, double m2 );
65
66 static QwtSplinePolynomial fromCurvatures(
67 const QPointF& p1, double cv1,
68 const QPointF& p2, double cv2 );
69
70 static QwtSplinePolynomial fromCurvatures(
71 double dx, double dy, double cv1, double cv2 );
72
73 public:
75 double c3;
76
78 double c2;
79
81 double c1;
82};
83
84Q_DECLARE_TYPEINFO( QwtSplinePolynomial, Q_MOVABLE_TYPE );
85Q_DECLARE_METATYPE( QwtSplinePolynomial )
86
87
94inline QwtSplinePolynomial::QwtSplinePolynomial( double a3, double a2, double a1 )
95 : c3( a3 )
96 , c2( a2 )
97 , c1( a1 )
98{
99}
100
106{
107 return ( c3 == other.c3 ) && ( c2 == other.c2 ) && ( c1 == other.c1 );
108}
109
115{
116 return ( !( *this == other ) );
117}
118
125inline double QwtSplinePolynomial::valueAt( double x ) const
126{
127 return ( ( ( c3 * x ) + c2 ) * x + c1 ) * x;
128}
129
136inline double QwtSplinePolynomial::slopeAt( double x ) const
137{
138 return ( 3.0 * c3 * x + 2.0 * c2 ) * x + c1;
139}
140
147inline double QwtSplinePolynomial::curvatureAt( double x ) const
148{
149 return 6.0 * c3 * x + 2.0 * c2;
150}
151
165 const QPointF& p1, double m1, const QPointF& p2, double m2 )
166{
167 return fromSlopes( p2.x() - p1.x(), p2.y() - p1.y(), m1, m2 );
168}
169
182 double dx, double dy, double m1, double m2 )
183{
184 const double c2 = ( 3.0 * dy / dx - 2 * m1 - m2 ) / dx;
185 const double c3 = ( ( m2 - m1 ) / dx - 2.0 * c2 ) / ( 3.0 * dx );
186
187 return QwtSplinePolynomial( c3, c2, m1 );
188}
189
203 const QPointF& p1, double cv1, const QPointF& p2, double cv2 )
204{
205 return fromCurvatures( p2.x() - p1.x(), p2.y() - p1.y(), cv1, cv2 );
206}
207
220 double dx, double dy, double cv1, double cv2 )
221{
222 const double c3 = ( cv2 - cv1 ) / ( 6.0 * dx );
223 const double c2 = 0.5 * cv1;
224 const double c1 = dy / dx - ( c3 * dx + c2 ) * dx;
225
226 return QwtSplinePolynomial( c3, c2, c1 );
227}
228
229#ifndef QT_NO_DEBUG_STREAM
230
231class QDebug;
232QWT_EXPORT QDebug operator<<( QDebug, const QwtSplinePolynomial& );
233
234#endif
235
236#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:136
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:164
double valueAt(double x) const
Calculate the value of a polynomial for a given x.
Definition qwt_spline_polynomial.h:125
bool operator==(const QwtSplinePolynomial &) const
Definition qwt_spline_polynomial.h:105
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:202
bool operator!=(const QwtSplinePolynomial &) const
Definition qwt_spline_polynomial.h:114
double c1
coefficient of the linear summand
Definition qwt_spline_polynomial.h:81
double c3
coefficient of the cubic summand
Definition qwt_spline_polynomial.h:75
double c2
coefficient of the quadratic summand
Definition qwt_spline_polynomial.h:78
double curvatureAt(double x) const
Calculate the value of the second derivate of a polynomial for a given x.
Definition qwt_spline_polynomial.h:147