Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00011 #ifndef _QWT_POINT_POLAR_H_
00012 #define _QWT_POINT_POLAR_H_ 1
00013
00014 #include "qwt_global.h"
00015 #include "qwt_math.h"
00016 #include <qpoint.h>
00017 #ifndef QT_NO_DEBUG_STREAM
00018 #include <qdebug.h>
00019 #endif
00020
00028 class QWT_EXPORT QwtPointPolar
00029 {
00030 public:
00031 QwtPointPolar();
00032 QwtPointPolar( double azimuth, double radius );
00033 QwtPointPolar( const QwtPointPolar & );
00034 QwtPointPolar( const QPointF & );
00035
00036 void setPoint( const QPointF & );
00037 QPointF toPoint() const;
00038
00039 bool isValid() const;
00040 bool isNull() const;
00041
00042 double radius() const;
00043 double azimuth() const;
00044
00045 double &rRadius();
00046 double &rAzimuth();
00047
00048 void setRadius( double );
00049 void setAzimuth( double );
00050
00051 bool operator==( const QwtPointPolar & ) const;
00052 bool operator!=( const QwtPointPolar & ) const;
00053
00054 QwtPointPolar normalized() const;
00055
00056 private:
00057 double d_azimuth;
00058 double d_radius;
00059 };
00060
00065 inline QwtPointPolar::QwtPointPolar():
00066 d_azimuth( 0.0 ),
00067 d_radius( 0.0 )
00068 {
00069 }
00070
00077 inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
00078 d_azimuth( azimuth ),
00079 d_radius( radius )
00080 {
00081 }
00082
00087 inline QwtPointPolar::QwtPointPolar( const QwtPointPolar &other ):
00088 d_azimuth( other.d_azimuth ),
00089 d_radius( other.d_radius )
00090 {
00091 }
00092
00094 inline bool QwtPointPolar::isValid() const
00095 {
00096 return d_radius >= 0.0;
00097 }
00098
00100 inline bool QwtPointPolar::isNull() const
00101 {
00102 return d_radius == 0.0;
00103 }
00104
00106 inline double QwtPointPolar::radius() const
00107 {
00108 return d_radius;
00109 }
00110
00112 inline double QwtPointPolar::azimuth() const
00113 {
00114 return d_azimuth;
00115 }
00116
00118 inline double &QwtPointPolar::rRadius()
00119 {
00120 return d_radius;
00121 }
00122
00124 inline double &QwtPointPolar::rAzimuth()
00125 {
00126 return d_azimuth;
00127 }
00128
00130 inline void QwtPointPolar::setRadius( double radius )
00131 {
00132 d_radius = radius;
00133 }
00134
00136 inline void QwtPointPolar::setAzimuth( double azimuth )
00137 {
00138 d_azimuth = azimuth;
00139 }
00140
00141 #ifndef QT_NO_DEBUG_STREAM
00142 QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
00143 #endif
00144
00145 inline QPoint qwtPolar2Pos( const QPoint &pole,
00146 double radius, double angle )
00147 {
00148 const double x = pole.x() + radius * qCos( angle );
00149 const double y = pole.y() - radius * qSin( angle );
00150
00151 return QPoint( qRound( x ), qRound( y ) );
00152 }
00153
00154 inline QPoint qwtDegree2Pos( const QPoint &pole,
00155 double radius, double angle )
00156 {
00157 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
00158 }
00159
00160 inline QPointF qwtPolar2Pos( const QPointF &pole,
00161 double radius, double angle )
00162 {
00163 const double x = pole.x() + radius * qCos( angle );
00164 const double y = pole.y() - radius * qSin( angle );
00165
00166 return QPointF( x, y);
00167 }
00168
00169 inline QPointF qwtDegree2Pos( const QPointF &pole,
00170 double radius, double angle )
00171 {
00172 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
00173 }
00174
00175 inline QPointF qwtFastPolar2Pos( const QPointF &pole,
00176 double radius, double angle )
00177 {
00178 #if QT_VERSION < 0x040601
00179 const double x = pole.x() + radius * ::cos( angle );
00180 const double y = pole.y() - radius * ::sin( angle );
00181 #else
00182 const double x = pole.x() + radius * qFastCos( angle );
00183 const double y = pole.y() - radius * qFastSin( angle );
00184 #endif
00185
00186 return QPointF( x, y);
00187 }
00188
00189 inline QPointF qwtFastDegree2Pos( const QPointF &pole,
00190 double radius, double angle )
00191 {
00192 return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
00193 }
00194
00195 inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos )
00196 {
00197 return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
00198 qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) );
00199 }
00200
00201 #endif