QWT 7.0.1
Loading...
Searching...
No Matches
qwt_point_polar.h
Go to the documentation of this file.
1/******************************************************************************
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 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
28#ifndef QWT_POINT_POLAR_H
29#define QWT_POINT_POLAR_H
30
31#include "qwt_global.h"
32#include "qwt_math.h"
33
34#include <qpoint.h>
35#include <qmetatype.h>
36#include <qmath.h>
37
45class QWT_EXPORT QwtPointPolar
46{
47 public:
49 QwtPointPolar( double azimuth, double radius );
50 QwtPointPolar( const QPointF& );
51
52 void setPoint( const QPointF& );
53 QPointF toPoint() const;
54
55 bool isValid() const;
56 bool isNull() const;
57
58 double radius() const;
59 double azimuth() const;
60
61 double& rRadius();
62 double& rAzimuth();
63
64 void setRadius( double );
65 void setAzimuth( double );
66
67 bool operator==( const QwtPointPolar& ) const;
68 bool operator!=( const QwtPointPolar& ) const;
69
70 QwtPointPolar normalized() const;
71
72 private:
73 double m_azimuth;
74 double m_radius;
75};
76
77Q_DECLARE_TYPEINFO( QwtPointPolar, Q_MOVABLE_TYPE );
78Q_DECLARE_METATYPE( QwtPointPolar );
79
80#ifndef QT_NO_DEBUG_STREAM
81QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar& );
82#endif
83
89 : m_azimuth( 0.0 )
90 , m_radius( 0.0 )
91{
92}
93
100inline QwtPointPolar::QwtPointPolar( double azimuth, double radius )
101 : m_azimuth( azimuth )
102 , m_radius( radius )
103{
104}
105
107inline bool QwtPointPolar::isValid() const
108{
109 return m_radius >= 0.0;
110}
111
113inline bool QwtPointPolar::isNull() const
114{
115 return m_radius == 0.0;
116}
117
119inline double QwtPointPolar::radius() const
120{
121 return m_radius;
122}
123
125inline double QwtPointPolar::azimuth() const
126{
127 return m_azimuth;
128}
129
132{
133 return m_radius;
134}
135
138{
139 return m_azimuth;
140}
141
143inline void QwtPointPolar::setRadius( double radius )
144{
145 m_radius = radius;
146}
147
149inline void QwtPointPolar::setAzimuth( double azimuth )
150{
151 m_azimuth = azimuth;
152}
153
154inline QPoint qwtPolar2Pos( const QPoint& pole,
155 double radius, double angle )
156{
157 const double x = pole.x() + radius * std::cos( angle );
158 const double y = pole.y() - radius * std::sin( angle );
159
160 return QPoint( qRound( x ), qRound( y ) );
161}
162
163inline QPoint qwtDegree2Pos( const QPoint& pole,
164 double radius, double angle )
165{
166 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
167}
168
169inline QPointF qwtPolar2Pos( const QPointF& pole,
170 double radius, double angle )
171{
172 const double x = pole.x() + radius * std::cos( angle );
173 const double y = pole.y() - radius * std::sin( angle );
174
175 return QPointF( x, y);
176}
177
178inline QPointF qwtDegree2Pos( const QPointF& pole,
179 double radius, double angle )
180{
181 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
182}
183
184inline QPointF qwtFastPolar2Pos( const QPointF& pole,
185 double radius, double angle )
186{
187 const double x = pole.x() + radius * qFastCos( angle );
188 const double y = pole.y() - radius * qFastSin( angle );
189
190 return QPointF( x, y);
191}
192
193inline QPointF qwtFastDegree2Pos( const QPointF& pole,
194 double radius, double angle )
195{
196 return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
197}
198
199inline QwtPointPolar qwtFastPos2Polar( const QPointF& pos )
200{
201 return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
202 qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) );
203}
204
205#endif
A point in polar coordinates.
Definition qwt_point_polar.h:46
double radius() const
Returns the radius.
Definition qwt_point_polar.h:119
void setRadius(double)
Sets the radius to radius.
Definition qwt_point_polar.h:143
void setAzimuth(double)
Sets the azimuth to azimuth.
Definition qwt_point_polar.h:149
QwtPointPolar()
Constructs a null point, with a radius and azimuth set to 0.0.
Definition qwt_point_polar.h:88
bool isValid() const
Returns true if radius() >= 0.0.
Definition qwt_point_polar.h:107
double azimuth() const
Returns the azimuth.
Definition qwt_point_polar.h:125
bool isNull() const
Returns true if radius() >= 0.0.
Definition qwt_point_polar.h:113
double & rRadius()
Returns the radius.
Definition qwt_point_polar.h:131
double & rAzimuth()
Returns the azimuth.
Definition qwt_point_polar.h:137