Qwt User's Guide 6.3.0

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
10#ifndef QWT_SPLINE_POLYNOMIAL_H
11#define QWT_SPLINE_POLYNOMIAL_H
12
13#include "qwt_global.h"
14
15#include <qpoint.h>
16#include <qmetatype.h>
17
30 class QWT_EXPORT QwtSplinePolynomial
31{
32 public:
33 QwtSplinePolynomial( double c3 = 0.0, double c2 = 0.0, double c1 = 0.0 );
34
35 bool operator==( const QwtSplinePolynomial& ) const;
36 bool operator!=( const QwtSplinePolynomial& ) const;
37
38 double valueAt( double x ) const;
39 double slopeAt( double x ) const;
40 double curvatureAt( double x ) const;
41
42 static QwtSplinePolynomial fromSlopes(
43 const QPointF& p1, double m1,
44 const QPointF& p2, double m2 );
45
46 static QwtSplinePolynomial fromSlopes(
47 double x, double y, double m1, double m2 );
48
49 static QwtSplinePolynomial fromCurvatures(
50 const QPointF& p1, double cv1,
51 const QPointF& p2, double cv2 );
52
53 static QwtSplinePolynomial fromCurvatures(
54 double dx, double dy, double cv1, double cv2 );
55
56 public:
58 double c3;
59
61 double c2;
62
64 double c1;
65};
66
67Q_DECLARE_TYPEINFO( QwtSplinePolynomial, Q_MOVABLE_TYPE );
68Q_DECLARE_METATYPE( QwtSplinePolynomial )
69
70
77inline QwtSplinePolynomial::QwtSplinePolynomial( double a3, double a2, double a1 )
78 : c3( a3 )
79 , c2( a2 )
80 , c1( a1 )
81{
82}
83
88 inline bool QwtSplinePolynomial::operator==( const QwtSplinePolynomial& other ) const
89{
90 return ( c3 == other.c3 ) && ( c2 == other.c2 ) && ( c1 == other.c1 );
91}
92
97 inline bool QwtSplinePolynomial::operator!=( const QwtSplinePolynomial& other ) const
98{
99 return ( !( *this == other ) );
100}
101
108 inline double QwtSplinePolynomial::valueAt( double x ) const
109{
110 return ( ( ( c3 * x ) + c2 ) * x + c1 ) * x;
111}
112
119 inline double QwtSplinePolynomial::slopeAt( double x ) const
120{
121 return ( 3.0 * c3 * x + 2.0 * c2 ) * x + c1;
122}
123
130 inline double QwtSplinePolynomial::curvatureAt( double x ) const
131{
132 return 6.0 * c3 * x + 2.0 * c2;
133}
134
147 inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes(
148 const QPointF& p1, double m1, const QPointF& p2, double m2 )
149{
150 return fromSlopes( p2.x() - p1.x(), p2.y() - p1.y(), m1, m2 );
151}
152
164 inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes(
165 double dx, double dy, double m1, double m2 )
166{
167 const double c2 = ( 3.0 * dy / dx - 2 * m1 - m2 ) / dx;
168 const double c3 = ( ( m2 - m1 ) / dx - 2.0 * c2 ) / ( 3.0 * dx );
169
170 return QwtSplinePolynomial( c3, c2, m1 );
171}
172
185 inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures(
186 const QPointF& p1, double cv1, const QPointF& p2, double cv2 )
187{
188 return fromCurvatures( p2.x() - p1.x(), p2.y() - p1.y(), cv1, cv2 );
189}
190
202 inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures(
203 double dx, double dy, double cv1, double cv2 )
204{
205 const double c3 = ( cv2 - cv1 ) / ( 6.0 * dx );
206 const double c2 = 0.5 * cv1;
207 const double c1 = dy / dx - ( c3 * dx + c2 ) * dx;
208
209 return QwtSplinePolynomial( c3, c2, c1 );
210}
211
212#ifndef QT_NO_DEBUG_STREAM
213
214 class QDebug;
215QWT_EXPORT QDebug operator<<( QDebug, const QwtSplinePolynomial& );
216
217#endif
218
219#endif
QwtSplinePolynomial
A cubic polynomial without constant term.
Definition qwt_spline_polynomial.h:31
QwtSplinePolynomial::slopeAt
double slopeAt(double x) const
Definition qwt_spline_polynomial.h:119
QwtSplinePolynomial::QwtSplinePolynomial
QwtSplinePolynomial(double c3=0.0, double c2=0.0, double c1=0.0)
Constructor.
Definition qwt_spline_polynomial.h:77
QwtSplinePolynomial::fromSlopes
static QwtSplinePolynomial fromSlopes(const QPointF &p1, double m1, const QPointF &p2, double m2)
Definition qwt_spline_polynomial.h:147
QwtSplinePolynomial::valueAt
double valueAt(double x) const
Definition qwt_spline_polynomial.h:108
QwtSplinePolynomial::operator==
bool operator==(const QwtSplinePolynomial &) const
Definition qwt_spline_polynomial.h:88
QwtSplinePolynomial::fromCurvatures
static QwtSplinePolynomial fromCurvatures(const QPointF &p1, double cv1, const QPointF &p2, double cv2)
Definition qwt_spline_polynomial.h:185
QwtSplinePolynomial::operator!=
bool operator!=(const QwtSplinePolynomial &) const
Definition qwt_spline_polynomial.h:97
QwtSplinePolynomial::c1
double c1
coefficient of the linear summand
Definition qwt_spline_polynomial.h:64
QwtSplinePolynomial::c3
double c3
coefficient of the cubic summand
Definition qwt_spline_polynomial.h:58
QwtSplinePolynomial::c2
double c2
coefficient of the quadratic summand
Definition qwt_spline_polynomial.h:61
QwtSplinePolynomial::curvatureAt
double curvatureAt(double x) const
Definition qwt_spline_polynomial.h:130