qwt_point_polar.h
Go to the documentation of this file.
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
13 
14 #include "qwt_global.h"
15 #include "qwt_math.h"
16 
17 #include <qpoint.h>
18 #include <qmath.h>
19 
28 {
29 public:
30  QwtPointPolar();
31  QwtPointPolar( double azimuth, double radius );
32  QwtPointPolar( const QPointF & );
33 
34  void setPoint( const QPointF & );
35  QPointF toPoint() const;
36 
37  bool isValid() const;
38  bool isNull() const;
39 
40  double radius() const;
41  double azimuth() const;
42 
43  double &rRadius();
44  double &rAzimuth();
45 
46  void setRadius( double );
47  void setAzimuth( double );
48 
49  bool operator==( const QwtPointPolar & ) const;
50  bool operator!=( const QwtPointPolar & ) const;
51 
52  QwtPointPolar normalized() const;
53 
54 private:
55  double d_azimuth;
56  double d_radius;
57 };
58 
64  d_azimuth( 0.0 ),
65  d_radius( 0.0 )
66 {
67 }
68 
75 inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
76  d_azimuth( azimuth ),
77  d_radius( radius )
78 {
79 }
80 
82 inline bool QwtPointPolar::isValid() const
83 {
84  return d_radius >= 0.0;
85 }
86 
88 inline bool QwtPointPolar::isNull() const
89 {
90  return d_radius == 0.0;
91 }
92 
94 inline double QwtPointPolar::radius() const
95 {
96  return d_radius;
97 }
98 
100 inline double QwtPointPolar::azimuth() const
101 {
102  return d_azimuth;
103 }
104 
106 inline double &QwtPointPolar::rRadius()
107 {
108  return d_radius;
109 }
110 
112 inline double &QwtPointPolar::rAzimuth()
113 {
114  return d_azimuth;
115 }
116 
118 inline void QwtPointPolar::setRadius( double radius )
119 {
120  d_radius = radius;
121 }
122 
124 inline void QwtPointPolar::setAzimuth( double azimuth )
125 {
126  d_azimuth = azimuth;
127 }
128 
129 #ifndef QT_NO_DEBUG_STREAM
130 QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
131 #endif
132 
133 inline QPoint qwtPolar2Pos( const QPoint &pole,
134  double radius, double angle )
135 {
136  const double x = pole.x() + radius * std::cos( angle );
137  const double y = pole.y() - radius * std::sin( angle );
138 
139  return QPoint( qRound( x ), qRound( y ) );
140 }
141 
142 inline QPoint qwtDegree2Pos( const QPoint &pole,
143  double radius, double angle )
144 {
145  return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
146 }
147 
148 inline QPointF qwtPolar2Pos( const QPointF &pole,
149  double radius, double angle )
150 {
151  const double x = pole.x() + radius * std::cos( angle );
152  const double y = pole.y() - radius * std::sin( angle );
153 
154  return QPointF( x, y);
155 }
156 
157 inline QPointF qwtDegree2Pos( const QPointF &pole,
158  double radius, double angle )
159 {
160  return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
161 }
162 
163 inline QPointF qwtFastPolar2Pos( const QPointF &pole,
164  double radius, double angle )
165 {
166  const double x = pole.x() + radius * qFastCos( angle );
167  const double y = pole.y() - radius * qFastSin( angle );
168 
169  return QPointF( x, y);
170 }
171 
172 inline QPointF qwtFastDegree2Pos( const QPointF &pole,
173  double radius, double angle )
174 {
175  return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
176 }
177 
178 inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos )
179 {
180  return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
181  qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) );
182 }
183 
184 #endif
void setAzimuth(double)
Sets the atimuth to atimuth.
A point in polar coordinates.
constexpr bool operator!=(const optional< T > &lhs, const optional< U > &rhs)
relop
Definition: sol.hpp:5324
bool operator==(fp x, fp y)
Definition: format-inl.h:1167
double & rRadius()
Returns the radius.
#define QWT_EXPORT
Definition: qwt_global.h:38
QPoint qwtPolar2Pos(const QPoint &pole, double radius, double angle)
QPointF qwtFastPolar2Pos(const QPointF &pole, double radius, double angle)
double radius() const
Returns the radius.
void setRadius(double)
Sets the radius to radius.
bool isNull() const
Returns true if radius() >= 0.0.
double azimuth() const
Returns the azimuth.
QwtPointPolar qwtFastPos2Polar(const QPointF &pos)
QPointF qwtFastDegree2Pos(const QPointF &pole, double radius, double angle)
double & rAzimuth()
Returns the azimuth.
bool isValid() const
Returns true if radius() >= 0.0.
#define M_PI
Definition: qwt_math.h:56
QPoint qwtDegree2Pos(const QPoint &pole, double radius, double angle)
QWT_EXPORT QDebug operator<<(QDebug, const QwtPointPolar &)
double qwtSqr(double x)
Return the square of a number.
Definition: qwt_math.h:191
double qwtFastAtan2(double y, double x)
Approximation of arc tangent ( error below 0,005 radians )
Definition: qwt_math.h:209


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10