Loading...
Searching...
No Matches
qwt_spline_polynomial.h
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef QWT_SPLINE_POLYNOMIAL_H
#define QWT_SPLINE_POLYNOMIAL_H
#include "qwt_global.h"
#include <qpoint.h>
#include <qmetatype.h>
class QWT_EXPORT QwtSplinePolynomial
{
public:
QwtSplinePolynomial( double c3 = 0.0, double c2 = 0.0, double c1 = 0.0 );
bool operator==( const QwtSplinePolynomial& ) const;
bool operator!=( const QwtSplinePolynomial& ) const;
double valueAt( double x ) const;
double slopeAt( double x ) const;
double curvatureAt( double x ) const;
static QwtSplinePolynomial fromSlopes(
const QPointF& p1, double m1,
const QPointF& p2, double m2 );
static QwtSplinePolynomial fromSlopes(
double x, double y, double m1, double m2 );
static QwtSplinePolynomial fromCurvatures(
const QPointF& p1, double cv1,
const QPointF& p2, double cv2 );
static QwtSplinePolynomial fromCurvatures(
double dx, double dy, double cv1, double cv2 );
public:
double c3;
double c2;
double c1;
};
Q_DECLARE_TYPEINFO( QwtSplinePolynomial, Q_MOVABLE_TYPE );
Q_DECLARE_METATYPE( QwtSplinePolynomial )
inline QwtSplinePolynomial::QwtSplinePolynomial( double a3, double a2, double a1 )
: c3( a3 )
, c2( a2 )
, c1( a1 )
{
}
inline bool QwtSplinePolynomial::operator==( const QwtSplinePolynomial& other ) const
{
return ( c3 == other.c3 ) && ( c2 == other.c2 ) && ( c1 == other.c1 );
}
inline bool QwtSplinePolynomial::operator!=( const QwtSplinePolynomial& other ) const
{
return ( !( *this == other ) );
}
inline double QwtSplinePolynomial::valueAt( double x ) const
{
return ( ( ( c3 * x ) + c2 ) * x + c1 ) * x;
}
inline double QwtSplinePolynomial::slopeAt( double x ) const
{
return ( 3.0 * c3 * x + 2.0 * c2 ) * x + c1;
}
inline double QwtSplinePolynomial::curvatureAt( double x ) const
{
return 6.0 * c3 * x + 2.0 * c2;
}
inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes(
const QPointF& p1, double m1, const QPointF& p2, double m2 )
{
return fromSlopes( p2.x() - p1.x(), p2.y() - p1.y(), m1, m2 );
}
inline QwtSplinePolynomial QwtSplinePolynomial::fromSlopes(
double dx, double dy, double m1, double m2 )
{
const double c2 = ( 3.0 * dy / dx - 2 * m1 - m2 ) / dx;
const double c3 = ( ( m2 - m1 ) / dx - 2.0 * c2 ) / ( 3.0 * dx );
return QwtSplinePolynomial( c3, c2, m1 );
}
inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures(
const QPointF& p1, double cv1, const QPointF& p2, double cv2 )
{
return fromCurvatures( p2.x() - p1.x(), p2.y() - p1.y(), cv1, cv2 );
}
inline QwtSplinePolynomial QwtSplinePolynomial::fromCurvatures(
double dx, double dy, double cv1, double cv2 )
{
const double c3 = ( cv2 - cv1 ) / ( 6.0 * dx );
const double c2 = 0.5 * cv1;
const double c1 = dy / dx - ( c3 * dx + c2 ) * dx;
return QwtSplinePolynomial( c3, c2, c1 );
}
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
QWT_EXPORT QDebug operator<<( QDebug, const QwtSplinePolynomial& );
#endif
#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