source: ntrip/trunk/BNC/qwt/qwt_point_polar.h@ 4275

Last change on this file since 4275 was 4271, checked in by mervart, 12 years ago
File size: 4.3 KB
Line 
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
10/*! \file */
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
21/*!
22 \brief A point in polar coordinates
23
24 In polar coordinates a point is determined by an angle and a distance.
25 See http://en.wikipedia.org/wiki/Polar_coordinate_system
26*/
27
28class QWT_EXPORT QwtPointPolar
29{
30public:
31 QwtPointPolar();
32 QwtPointPolar( double azimuth, double radius );
33 QwtPointPolar( const QwtPointPolar & );
34 QwtPointPolar( const QPointF & );
35
36 void setPoint( const QPointF & );
37 QPointF toPoint() const;
38
39 bool isValid() const;
40 bool isNull() const;
41
42 double radius() const;
43 double azimuth() const;
44
45 double &rRadius();
46 double &rAzimuth();
47
48 void setRadius( double );
49 void setAzimuth( double );
50
51 bool operator==( const QwtPointPolar & ) const;
52 bool operator!=( const QwtPointPolar & ) const;
53
54 QwtPointPolar normalized() const;
55
56private:
57 double d_azimuth;
58 double d_radius;
59};
60
61/*!
62 Constructs a null point, with a radius and azimuth set to 0.0.
63 \sa QPointF::isNull
64*/
65inline QwtPointPolar::QwtPointPolar():
66 d_azimuth( 0.0 ),
67 d_radius( 0.0 )
68{
69}
70
71/*!
72 Constructs a point with coordinates specified by radius and azimuth.
73
74 \param azimuth Azimuth
75 \param radius Radius
76*/
77inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
78 d_azimuth( azimuth ),
79 d_radius( radius )
80{
81}
82
83/*!
84 Constructs a point using the values of the point specified.
85 \param other Other point
86*/
87inline QwtPointPolar::QwtPointPolar( const QwtPointPolar &other ):
88 d_azimuth( other.d_azimuth ),
89 d_radius( other.d_radius )
90{
91}
92
93//! Returns true if radius() >= 0.0
94inline bool QwtPointPolar::isValid() const
95{
96 return d_radius >= 0.0;
97}
98
99//! Returns true if radius() >= 0.0
100inline bool QwtPointPolar::isNull() const
101{
102 return d_radius == 0.0;
103}
104
105//! Returns the radius.
106inline double QwtPointPolar::radius() const
107{
108 return d_radius;
109}
110
111//! Returns the azimuth.
112inline double QwtPointPolar::azimuth() const
113{
114 return d_azimuth;
115}
116
117//! Returns the radius.
118inline double &QwtPointPolar::rRadius()
119{
120 return d_radius;
121}
122
123//! Returns the azimuth.
124inline double &QwtPointPolar::rAzimuth()
125{
126 return d_azimuth;
127}
128
129//! Sets the radius to radius.
130inline void QwtPointPolar::setRadius( double radius )
131{
132 d_radius = radius;
133}
134
135//! Sets the atimuth to atimuth.
136inline void QwtPointPolar::setAzimuth( double azimuth )
137{
138 d_azimuth = azimuth;
139}
140
141#ifndef QT_NO_DEBUG_STREAM
142QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
143#endif
144
145inline QPoint qwtPolar2Pos( const QPoint &pole,
146 double radius, double angle )
147{
148 const double x = pole.x() + radius * qCos( angle );
149 const double y = pole.y() - radius * qSin( angle );
150
151 return QPoint( qRound( x ), qRound( y ) );
152}
153
154inline QPoint qwtDegree2Pos( const QPoint &pole,
155 double radius, double angle )
156{
157 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
158}
159
160inline QPointF qwtPolar2Pos( const QPointF &pole,
161 double radius, double angle )
162{
163 const double x = pole.x() + radius * qCos( angle );
164 const double y = pole.y() - radius * qSin( angle );
165
166 return QPointF( x, y);
167}
168
169inline QPointF qwtDegree2Pos( const QPointF &pole,
170 double radius, double angle )
171{
172 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
173}
174
175inline QPointF qwtFastPolar2Pos( const QPointF &pole,
176 double radius, double angle )
177{
178#if QT_VERSION < 0x040601
179 const double x = pole.x() + radius * ::cos( angle );
180 const double y = pole.y() - radius * ::sin( angle );
181#else
182 const double x = pole.x() + radius * qFastCos( angle );
183 const double y = pole.y() - radius * qFastSin( angle );
184#endif
185
186 return QPointF( x, y);
187}
188
189inline QPointF qwtFastDegree2Pos( const QPointF &pole,
190 double radius, double angle )
191{
192 return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
193}
194
195#endif
Note: See TracBrowser for help on using the repository browser.