Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_point_polar.h
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
11#ifndef QWT_POINT_POLAR_H
12#define QWT_POINT_POLAR_H
13
14#include "qwt_global.h"
15#include "qwt_math.h"
16
17#include <qpoint.h>
18#include <qmetatype.h>
19#include <qmath.h>
20
28class QWT_EXPORT QwtPointPolar
29{
30 public:
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 m_azimuth;
57 double m_radius;
58};
59
60Q_DECLARE_TYPEINFO( QwtPointPolar, Q_MOVABLE_TYPE );
61Q_DECLARE_METATYPE( QwtPointPolar )
62
63#ifndef QT_NO_DEBUG_STREAM
64QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar& );
65#endif
66
72 : m_azimuth( 0.0 )
73 , m_radius( 0.0 )
74{
75}
76
83inline QwtPointPolar::QwtPointPolar( double azimuth, double radius )
84 : m_azimuth( azimuth )
85 , m_radius( radius )
86{
87}
88
90inline bool QwtPointPolar::isValid() const
91{
92 return m_radius >= 0.0;
93}
94
96inline bool QwtPointPolar::isNull() const
97{
98 return m_radius == 0.0;
99}
100
102inline double QwtPointPolar::radius() const
103{
104 return m_radius;
105}
106
108inline double QwtPointPolar::azimuth() const
109{
110 return m_azimuth;
111}
112
115{
116 return m_radius;
117}
118
121{
122 return m_azimuth;
123}
124
126inline void QwtPointPolar::setRadius( double radius )
127{
128 m_radius = radius;
129}
130
132inline void QwtPointPolar::setAzimuth( double azimuth )
133{
134 m_azimuth = azimuth;
135}
136
137inline QPoint qwtPolar2Pos( const QPoint& pole,
138 double radius, double angle )
139{
140 const double x = pole.x() + radius * std::cos( angle );
141 const double y = pole.y() - radius * std::sin( angle );
142
143 return QPoint( qRound( x ), qRound( y ) );
144}
145
146inline QPoint qwtDegree2Pos( const QPoint& pole,
147 double radius, double angle )
148{
149 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
150}
151
152inline QPointF qwtPolar2Pos( const QPointF& pole,
153 double radius, double angle )
154{
155 const double x = pole.x() + radius * std::cos( angle );
156 const double y = pole.y() - radius * std::sin( angle );
157
158 return QPointF( x, y);
159}
160
161inline QPointF qwtDegree2Pos( const QPointF& pole,
162 double radius, double angle )
163{
164 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
165}
166
167inline QPointF qwtFastPolar2Pos( const QPointF& pole,
168 double radius, double angle )
169{
170 const double x = pole.x() + radius * qFastCos( angle );
171 const double y = pole.y() - radius * qFastSin( angle );
172
173 return QPointF( x, y);
174}
175
176inline QPointF qwtFastDegree2Pos( const QPointF& pole,
177 double radius, double angle )
178{
179 return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
180}
181
182inline QwtPointPolar qwtFastPos2Polar( const QPointF& pos )
183{
184 return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
185 qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) );
186}
187
188#endif
A point in polar coordinates.
double radius() const
Returns the radius.
void setRadius(double)
Sets the radius to radius.
void setAzimuth(double)
Sets the azimuth to azimuth.
bool isValid() const
Returns true if radius() >= 0.0.
double azimuth() const
Returns the azimuth.
bool isNull() const
Returns true if radius() >= 0.0.
double & rRadius()
Returns the radius.
double & rAzimuth()
Returns the azimuth.