qwt_spline_polynomial.h
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 
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 
74 inline QwtSplinePolynomial::QwtSplinePolynomial( double a3, double a2, double a1 ):
75  c3(a3),
76  c2(a2),
77  c1(a1)
78 {
79 }
80 
85 inline bool QwtSplinePolynomial::operator==( const QwtSplinePolynomial &other ) const
86 {
87  return ( c3 == other.c3 ) && ( c2 == other.c2 ) && ( c1 == other.c1 );
88 }
89 
94 inline bool QwtSplinePolynomial::operator!=( const QwtSplinePolynomial &other ) const
95 {
96  return ( !( *this == other ) );
97 }
98 
105 inline double QwtSplinePolynomial::valueAt( double x ) const
106 {
107  return ( ( ( c3 * x ) + c2 ) * x + c1 ) * x;
108 }
109 
116 inline double QwtSplinePolynomial::slopeAt( double x ) const
117 {
118  return ( 3.0 * c3 * x + 2.0 * c2 ) * x + c1;
119 }
120 
127 inline double QwtSplinePolynomial::curvatureAt( double x ) const
128 {
129  return 6.0 * c3 * x + 2.0 * c2;
130 }
131 
145  const QPointF &p1, double m1, const QPointF &p2, double m2 )
146 {
147  return fromSlopes( p2.x() - p1.x(), p2.y() - p1.y(), m1, m2 );
148 }
149 
162  double dx, double dy, double m1, double m2 )
163 {
164  const double c2 = ( 3.0 * dy / dx - 2 * m1 - m2 ) / dx;
165  const double c3 = ( ( m2 - m1 ) / dx - 2.0 * c2 ) / ( 3.0 * dx );
166 
167  return QwtSplinePolynomial( c3, c2, m1 );
168 }
169 
183  const QPointF &p1, double cv1, const QPointF &p2, double cv2 )
184 {
185  return fromCurvatures( p2.x() - p1.x(), p2.y() - p1.y(), cv1, cv2 );
186 }
187 
200  double dx, double dy, double cv1, double cv2 )
201 {
202  const double c3 = ( cv2 - cv1 ) / ( 6.0 * dx );
203  const double c2 = 0.5 * cv1;
204  const double c1 = dy / dx - ( c3 * dx + c2 ) * dx;
205 
206  return QwtSplinePolynomial( c3, c2, c1 );
207 }
208 
209 Q_DECLARE_METATYPE( QwtSplinePolynomial )
210 
211 #ifndef QT_NO_DEBUG_STREAM
212 
213 #include <qdebug.h>
214 
215 inline QDebug operator<<( QDebug debug, const QwtSplinePolynomial &polynomial )
216 {
217  debug.nospace() << "Polynom(" << polynomial.c3 << ", "
218  << polynomial.c2 << ", " << polynomial.c1 << ")";
219  return debug.space();
220 }
221 #endif
222 
223 #endif
double c1
coefficient of the linear summand
double slopeAt(double x) const
constexpr bool operator!=(const optional< T > &lhs, const optional< U > &rhs)
relop
Definition: sol.hpp:5324
bool operator==(fp x, fp y)
Definition: format-inl.h:1167
QwtSplinePolynomial(double c3=0.0, double c2=0.0, double c1=0.0)
Constructor.
#define QWT_EXPORT
Definition: qwt_global.h:38
bool operator!=(const QwtSplinePolynomial &) const
double valueAt(double x) const
QDebug operator<<(QDebug debug, const QwtSplinePolynomial &polynomial)
bool operator==(const QwtSplinePolynomial &) const
A cubic polynomial without constant term.
double c2
coefficient of the quadratic summand
double c3
coefficient of the cubic summand
static QwtSplinePolynomial fromSlopes(const QPointF &p1, double m1, const QPointF &p2, double m2)
static QwtSplinePolynomial fromCurvatures(const QPointF &p1, double cv1, const QPointF &p2, double cv2)
double curvatureAt(double x) const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10