QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgssphere.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssphere.h
3 --------------
4 begin : July 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSSPHERE_H
19#define QGSSPHERE_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgis.h"
24#include <limits>
25
26class QgsPoint;
27class QgsCircle;
28class QgsBox3D;
29class QgsVector3D;
30
40class CORE_EXPORT QgsSphere
41{
42
43 public:
44
49
53 QgsSphere( double x, double y, double z, double radius ) SIP_HOLDGIL;
54
55 bool operator==( const QgsSphere &other ) const
56 {
57 return qgsDoubleNear( mCenterX, other.mCenterX ) && qgsDoubleNear( mCenterY, other.mCenterY ) && qgsDoubleNear( mCenterZ, other.mCenterZ ) && qgsDoubleNear( mRadius, other.mRadius );
58 }
59 bool operator!=( const QgsSphere &other ) const { return !( *this == other ); }
60
64 bool isNull() const SIP_HOLDGIL;
65
69 bool isEmpty() const SIP_HOLDGIL;
70
79 QgsPoint center() const SIP_HOLDGIL;
80
89 QgsVector3D centerVector() const SIP_HOLDGIL;
90
99 double centerX() const { return mCenterX; }
100
109 double centerY() const { return mCenterY; }
110
119 double centerZ() const { return mCenterZ; }
120
125 void setCenter( const QgsPoint &center ) SIP_HOLDGIL;
126
131 void setCenter( double x, double y, double z ) SIP_HOLDGIL { mCenterX = x; mCenterY = y; mCenterZ = z; }
132
139 double radius() const SIP_HOLDGIL { return mRadius; }
140
146 void setRadius( double radius ) SIP_HOLDGIL{ mRadius = radius; }
147
153 double diameter() const SIP_HOLDGIL { return mRadius * 2; }
154
158 double volume() const SIP_HOLDGIL;
159
163 double surfaceArea() const SIP_HOLDGIL;
164
168 QgsCircle toCircle() const SIP_HOLDGIL;
169
173 QgsBox3D boundingBox() const SIP_HOLDGIL;
174
175#ifdef SIP_RUN
176 SIP_PYOBJECT __repr__();
177 % MethodCode
178 QString str;
179 if ( sipCpp->isNull() )
180 {
181 str = QStringLiteral( "<QgsSphere: null>" ).arg( sipCpp->centerX() ).arg( sipCpp->centerY() ).arg( sipCpp->centerZ() ).arg( sipCpp->radius() );
182 }
183 else
184 {
185 str = QStringLiteral( "<QgsSphere: (%1, %2, %3) radius %4>" ).arg( sipCpp->centerX() ).arg( sipCpp->centerY() ).arg( sipCpp->centerZ() ).arg( sipCpp->radius() );
186 }
187 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
188 % End
189#endif
190
191 private:
192 double mCenterX = std::numeric_limits< double >::quiet_NaN();
193 double mCenterY = std::numeric_limits< double >::quiet_NaN();
194 double mCenterZ = std::numeric_limits< double >::quiet_NaN();
195 double mRadius = 0;
196
197};
198
199#endif // QGSSPHERE_H
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
Circle geometry type.
Definition qgscircle.h:43
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
A spherical geometry object.
Definition qgssphere.h:41
QgsSphere()=default
Constructor for an invalid QgsSphere.
double centerY() const
Returns the y-coordinate of the center of the sphere.
Definition qgssphere.h:109
double radius() const
Returns the radius of the sphere.
Definition qgssphere.h:139
double diameter() const
Returns the diameter of the sphere.
Definition qgssphere.h:153
void setCenter(double x, double y, double z)
Sets the center point of the sphere to (x, y, z).
Definition qgssphere.h:131
bool operator!=(const QgsSphere &other) const
Definition qgssphere.h:59
double centerZ() const
Returns the z-coordinate of the center of the sphere.
Definition qgssphere.h:119
void setRadius(double radius)
Sets the radius of the sphere.
Definition qgssphere.h:146
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
#define str(x)
Definition qgis.cpp:38
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5917
#define SIP_HOLDGIL
Definition qgis_sip.h:171