Qwt User's Guide  6.1.6
qwt_point_polar.h
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 
11 #ifndef _QWT_POINT_POLAR_H_
12 #define _QWT_POINT_POLAR_H_ 1
13 
14 #include "qwt_global.h"
15 #include "qwt_math.h"
16 #include <qpoint.h>
17 #ifndef QT_NO_DEBUG_STREAM
18 #include <qdebug.h>
19 #endif
20 
28 class QWT_EXPORT QwtPointPolar
29 {
30 public:
31  QwtPointPolar();
32  QwtPointPolar( double azimuth, double radius );
33  QwtPointPolar( const QPointF & );
34 
35  void setPoint( const QPointF & );
36  QPointF toPoint() const;
37 
38  bool isValid() const;
39  bool isNull() const;
40 
41  double radius() const;
42  double azimuth() const;
43 
44  double &rRadius();
45  double &rAzimuth();
46 
47  void setRadius( double );
48  void setAzimuth( double );
49 
50  bool operator==( const QwtPointPolar & ) const;
51  bool operator!=( const QwtPointPolar & ) const;
52 
53  QwtPointPolar normalized() const;
54 
55 private:
56  double d_azimuth;
57  double d_radius;
58 };
59 
65  d_azimuth( 0.0 ),
66  d_radius( 0.0 )
67 {
68 }
69 
76 inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
77  d_azimuth( azimuth ),
78  d_radius( radius )
79 {
80 }
81 
83 inline bool QwtPointPolar::isValid() const
84 {
85  return d_radius >= 0.0;
86 }
87 
89 inline bool QwtPointPolar::isNull() const
90 {
91  return d_radius == 0.0;
92 }
93 
95 inline double QwtPointPolar::radius() const
96 {
97  return d_radius;
98 }
99 
101 inline double QwtPointPolar::azimuth() const
102 {
103  return d_azimuth;
104 }
105 
107 inline double &QwtPointPolar::rRadius()
108 {
109  return d_radius;
110 }
111 
113 inline double &QwtPointPolar::rAzimuth()
114 {
115  return d_azimuth;
116 }
117 
119 inline void QwtPointPolar::setRadius( double radius )
120 {
121  d_radius = radius;
122 }
123 
125 inline void QwtPointPolar::setAzimuth( double azimuth )
126 {
127  d_azimuth = azimuth;
128 }
129 
130 #ifndef QT_NO_DEBUG_STREAM
131 QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
132 #endif
133 
134 inline QPoint qwtPolar2Pos( const QPoint &pole,
135  double radius, double angle )
136 {
137  const double x = pole.x() + radius * qCos( angle );
138  const double y = pole.y() - radius * qSin( angle );
139 
140  return QPoint( qRound( x ), qRound( y ) );
141 }
142 
143 inline QPoint qwtDegree2Pos( const QPoint &pole,
144  double radius, double angle )
145 {
146  return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
147 }
148 
149 inline QPointF qwtPolar2Pos( const QPointF &pole,
150  double radius, double angle )
151 {
152  const double x = pole.x() + radius * qCos( angle );
153  const double y = pole.y() - radius * qSin( angle );
154 
155  return QPointF( x, y);
156 }
157 
158 inline QPointF qwtDegree2Pos( const QPointF &pole,
159  double radius, double angle )
160 {
161  return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
162 }
163 
164 inline QPointF qwtFastPolar2Pos( const QPointF &pole,
165  double radius, double angle )
166 {
167 #if QT_VERSION < 0x040601
168  const double x = pole.x() + radius * ::cos( angle );
169  const double y = pole.y() - radius * ::sin( angle );
170 #else
171  const double x = pole.x() + radius * qFastCos( angle );
172  const double y = pole.y() - radius * qFastSin( angle );
173 #endif
174 
175  return QPointF( x, y);
176 }
177 
178 inline QPointF qwtFastDegree2Pos( const QPointF &pole,
179  double radius, double angle )
180 {
181  return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
182 }
183 
184 inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos )
185 {
186  return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
187  qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) );
188 }
189 
190 #endif
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition: qwt_point_polar.h:95
QwtPointPolar::isNull
bool isNull() const
Returns true if radius() >= 0.0.
Definition: qwt_point_polar.h:89
QwtPointPolar::isValid
bool isValid() const
Returns true if radius() >= 0.0.
Definition: qwt_point_polar.h:83
QwtPointPolar::setAzimuth
void setAzimuth(double)
Sets the atimuth to atimuth.
Definition: qwt_point_polar.h:125
QwtPointPolar::rRadius
double & rRadius()
Returns the radius.
Definition: qwt_point_polar.h:107
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:29
QwtPointPolar::rAzimuth
double & rAzimuth()
Returns the azimuth.
Definition: qwt_point_polar.h:113
QwtPointPolar::QwtPointPolar
QwtPointPolar()
Definition: qwt_point_polar.h:64
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition: qwt_point_polar.h:101
QwtPointPolar::setRadius
void setRadius(double)
Sets the radius to radius.
Definition: qwt_point_polar.h:119