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 1
12 
13 #include "qwt_global.h"
14 #include <qpoint.h>
15 #include <qmetatype.h>
16 
17 #ifndef QT_NO_DEBUG_STREAM
18 #include <qdebug.h>
19 #endif
20 
34 {
35 public:
36  QwtSplinePolynomial( double c3 = 0.0, double c2 = 0.0, double c1 = 0.0 );
37 
38  bool operator==( const QwtSplinePolynomial & ) const;
39  bool operator!=( const QwtSplinePolynomial & ) const;
40 
41  double valueAt( double x ) const;
42  double slopeAt( double x ) const;
43  double curvatureAt( double x ) const;
44 
45  static QwtSplinePolynomial fromSlopes(
46  const QPointF &p1, double m1,
47  const QPointF &p2, double m2 );
48 
49  static QwtSplinePolynomial fromSlopes(
50  double x, double y, double m1, double m2 );
51 
52  static QwtSplinePolynomial fromCurvatures(
53  const QPointF &p1, double cv1,
54  const QPointF &p2, double cv2 );
55 
56  static QwtSplinePolynomial fromCurvatures(
57  double dx, double dy, double cv1, double cv2 );
58 
59 public:
61  double c3;
62 
64  double c2;
65 
67  double c1;
68 };
69 
77 inline 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 
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 
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 
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 
203  double x, double y, double cv1, double cv2 )
204 {
205  const double c3 = ( cv2 - cv1 ) / ( 6.0 * x );
206  const double c2 = 0.5 * cv1;
207  const double c1 = y / x - ( c3 * x + c2 ) * x;
208 
209  return QwtSplinePolynomial( c3, c2, c1 );
210 }
211 
212 Q_DECLARE_METATYPE( QwtSplinePolynomial )
213 
214 #ifndef QT_NO_DEBUG_STREAM
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
QwtSplinePolynomial(double c3=0.0, double c2=0.0, double c1=0.0)
Constructor.
#define QWT_EXPORT
Definition: qwt_global.h:38
bool operator==(optional< T > const &x, optional< T > const &y)
Definition: optional.hpp:854
bool operator!=(const QwtSplinePolynomial &) const
double valueAt(double x) const
QDebug operator<<(QDebug debug, const QwtSplinePolynomial &polynomial)
TFSIMD_FORCE_INLINE const tfScalar & y() const
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
TFSIMD_FORCE_INLINE const tfScalar & x() const
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
bool operator!=(optional< T > const &x, optional< T > const &y)
Definition: optional.hpp:859


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18