qwt_spline_polynomial.h
Go to the documentation of this file.
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #ifndef QWT_SPLINE_POLYNOMIAL_H
00011 #define QWT_SPLINE_POLYNOMIAL_H 1
00012 
00013 #include "qwt_global.h"
00014 #include <qpoint.h>
00015 #include <qmetatype.h>
00016 
00017 #ifndef QT_NO_DEBUG_STREAM
00018 #include <qdebug.h>
00019 #endif
00020 
00033 class QWT_EXPORT QwtSplinePolynomial
00034 {
00035 public:
00036     QwtSplinePolynomial( double c3 = 0.0, double c2 = 0.0, double c1 = 0.0 );
00037 
00038     bool operator==( const QwtSplinePolynomial & ) const;
00039     bool operator!=( const QwtSplinePolynomial & ) const;
00040 
00041     double valueAt( double x ) const;
00042     double slopeAt( double x ) const;
00043     double curvatureAt( double x ) const;
00044 
00045     static QwtSplinePolynomial fromSlopes( 
00046         const QPointF &p1, double m1, 
00047         const QPointF &p2, double m2 );
00048 
00049     static QwtSplinePolynomial fromSlopes( 
00050         double x, double y, double m1, double m2 );
00051 
00052     static QwtSplinePolynomial fromCurvatures( 
00053         const QPointF &p1, double cv1,
00054         const QPointF &p2, double cv2 );
00055     
00056     static QwtSplinePolynomial fromCurvatures(
00057         double dx, double dy, double cv1, double cv2 );
00058 
00059 public:
00061     double c3;
00062 
00064     double c2;
00065 
00067     double c1;
00068 };
00069 
00077 inline QwtSplinePolynomial::QwtSplinePolynomial( double a3, double a2, double a1 ):
00078     c3(a3),
00079     c2(a2),
00080     c1(a1)
00081 {
00082 }
00083 
00088 inline bool QwtSplinePolynomial::operator==( const QwtSplinePolynomial &other ) const
00089 {
00090     return ( c3 == other.c3 ) && ( c2 == other.c2 ) && ( c1 == other.c1 );
00091 }
00092 
00097 inline bool QwtSplinePolynomial::operator!=( const QwtSplinePolynomial &other ) const
00098 {
00099     return ( !( *this == other ) );
00100 }
00101 
00108 inline double QwtSplinePolynomial::valueAt( double x ) const
00109 {
00110     return ( ( ( c3 * x ) + c2 ) * x + c1 ) * x;
00111 }   
00112 
00119 inline double QwtSplinePolynomial::slopeAt( double x ) const
00120 {   
00121     return ( 3.0 * c3 * x + 2.0 * c2 ) * x + c1;
00122 }
00123 
00130 inline double QwtSplinePolynomial::curvatureAt( double x ) const
00131 {   
00132     return 6.0 * c3 * x + 2.0 * c2;
00133 }
00134 
00147 inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes( 
00148     const QPointF &p1, double m1, const QPointF &p2, double m2 )
00149 {
00150     return fromSlopes( p2.x() - p1.x(), p2.y() - p1.y(), m1, m2 );
00151 }
00152 
00164 inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes( 
00165     double dx, double dy, double m1, double m2 )
00166 {
00167     const double c2 = ( 3.0 * dy / dx - 2 * m1 - m2 ) / dx;
00168     const double c3 = ( ( m2 - m1 ) / dx - 2.0 * c2 ) / ( 3.0 * dx );
00169 
00170     return QwtSplinePolynomial( c3, c2, m1 );
00171 }
00172 
00185 inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures( 
00186     const QPointF &p1, double cv1, const QPointF &p2, double cv2 )
00187 {
00188     return fromCurvatures( p2.x() - p1.x(), p2.y() - p1.y(), cv1, cv2 );
00189 }
00190 
00202 inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures( 
00203     double x, double y, double cv1, double cv2 )
00204 {
00205     const double c3 = ( cv2 - cv1 ) / ( 6.0 * x );
00206     const double c2 = 0.5 * cv1;
00207     const double c1 = y / x - ( c3 * x + c2 ) * x;
00208 
00209     return QwtSplinePolynomial( c3, c2, c1 );
00210 }
00211 
00212 Q_DECLARE_METATYPE( QwtSplinePolynomial )
00213 
00214 #ifndef QT_NO_DEBUG_STREAM
00215 inline QDebug operator<<( QDebug debug, const QwtSplinePolynomial &polynomial )
00216 {
00217     debug.nospace() << "Polynom(" << polynomial.c3 << ", "
00218         << polynomial.c2 << ", " << polynomial.c1 << ")";
00219     return debug.space();
00220 }
00221 #endif
00222 
00223 #endif


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:57