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

Last change on this file since 7196 was 4331, 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
56 double _value; // Change by LM
57
58private:
59 double d_azimuth;
60 double d_radius;
61};
62
63/*!
64 Constructs a null point, with a radius and azimuth set to 0.0.
65 \sa QPointF::isNull
66*/
67inline QwtPointPolar::QwtPointPolar():
68 d_azimuth( 0.0 ),
69 d_radius( 0.0 )
70{
71}
72
73/*!
74 Constructs a point with coordinates specified by radius and azimuth.
75
76 \param azimuth Azimuth
77 \param radius Radius
78*/
79inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
80 d_azimuth( azimuth ),
81 d_radius( radius )
82{
83}
84
85/*!
86 Constructs a point using the values of the point specified.
87 \param other Other point
88*/
89inline QwtPointPolar::QwtPointPolar( const QwtPointPolar &other ):
90 d_azimuth( other.d_azimuth ),
91 d_radius( other.d_radius )
92{
93}
94
95//! Returns true if radius() >= 0.0
96inline bool QwtPointPolar::isValid() const
97{
98 return d_radius >= 0.0;
99}
100
101//! Returns true if radius() >= 0.0
102inline bool QwtPointPolar::isNull() const
103{
104 return d_radius == 0.0;
105}
106
107//! Returns the radius.
108inline double QwtPointPolar::radius() const
109{
110 return d_radius;
111}
112
113//! Returns the azimuth.
114inline double QwtPointPolar::azimuth() const
115{
116 return d_azimuth;
117}
118
119//! Returns the radius.
120inline double &QwtPointPolar::rRadius()
121{
122 return d_radius;
123}
124
125//! Returns the azimuth.
126inline double &QwtPointPolar::rAzimuth()
127{
128 return d_azimuth;
129}
130
131//! Sets the radius to radius.
132inline void QwtPointPolar::setRadius( double radius )
133{
134 d_radius = radius;
135}
136
137//! Sets the atimuth to atimuth.
138inline void QwtPointPolar::setAzimuth( double azimuth )
139{
140 d_azimuth = azimuth;
141}
142
143#ifndef QT_NO_DEBUG_STREAM
144QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
145#endif
146
147inline QPoint qwtPolar2Pos( const QPoint &pole,
148 double radius, double angle )
149{
150 const double x = pole.x() + radius * qCos( angle );
151 const double y = pole.y() - radius * qSin( angle );
152
153 return QPoint( qRound( x ), qRound( y ) );
154}
155
156inline QPoint qwtDegree2Pos( const QPoint &pole,
157 double radius, double angle )
158{
159 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
160}
161
162inline QPointF qwtPolar2Pos( const QPointF &pole,
163 double radius, double angle )
164{
165 const double x = pole.x() + radius * qCos( angle );
166 const double y = pole.y() - radius * qSin( angle );
167
168 return QPointF( x, y);
169}
170
171inline QPointF qwtDegree2Pos( const QPointF &pole,
172 double radius, double angle )
173{
174 return qwtPolar2Pos( pole, radius, angle / 180.0 * M_PI );
175}
176
177inline QPointF qwtFastPolar2Pos( const QPointF &pole,
178 double radius, double angle )
179{
180#if QT_VERSION < 0x040601
181 const double x = pole.x() + radius * ::cos( angle );
182 const double y = pole.y() - radius * ::sin( angle );
183#else
184 const double x = pole.x() + radius * qFastCos( angle );
185 const double y = pole.y() - radius * qFastSin( angle );
186#endif
187
188 return QPointF( x, y);
189}
190
191inline QPointF qwtFastDegree2Pos( const QPointF &pole,
192 double radius, double angle )
193{
194 return qwtFastPolar2Pos( pole, radius, angle / 180.0 * M_PI );
195}
196
197#endif
Note: See TracBrowser for help on using the repository browser.