QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgssphere.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssphere.cpp
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#include "qgssphere.h"
19
20#include "qgsbox3d.h"
21#include "qgscircle.h"
22#include "qgspoint.h"
23#include "qgsvector3d.h"
24
25QgsSphere::QgsSphere( double x, double y, double z, double radius )
26 : mCenterX( x )
27 , mCenterY( y )
28 , mCenterZ( z )
29 , mRadius( radius )
30{
31
32}
33
35{
36 return std::isnan( mCenterX ) || std::isnan( mCenterY ) || std::isnan( mCenterZ );
37}
38
40{
41 return qgsDoubleNear( mRadius, 0 );
42}
43
45{
46 return QgsPoint( mCenterX, mCenterY, mCenterZ );
47}
48
50{
51 return QgsVector3D( mCenterX, mCenterY, mCenterZ );
52}
53
55{
56 mCenterX = center.x();
57 mCenterY = center.y();
58 mCenterZ = center.z();
59}
60
61double QgsSphere::volume() const
62{
63 return 4.0 / 3.0 * M_PI * std::pow( mRadius, 3 );
64}
65
67{
68 return 4.0 * M_PI * std::pow( mRadius, 2 );
69}
70
72{
73 if ( isNull() )
74 return QgsCircle();
75
76 return QgsCircle( QgsPoint( mCenterX, mCenterY ), mRadius );
77}
78
80{
81 if ( isNull() )
82 return QgsBox3D();
83
84 return QgsBox3D( mCenterX - mRadius, mCenterY - mRadius, mCenterZ - mRadius,
85 mCenterX + mRadius, mCenterY + mRadius, mCenterZ + mRadius );
86}
87
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:42
Circle geometry type.
Definition qgscircle.h:44
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
QgsCircle toCircle() const
Converts the sphere to a 2-dimensional circle.
Definition qgssphere.cpp:71
void setCenter(const QgsPoint &center)
Sets the center point of the sphere.
Definition qgssphere.cpp:54
double surfaceArea() const
Returns the surface area of the sphere.
Definition qgssphere.cpp:66
QgsVector3D centerVector() const
Returns the vector to the center of the sphere.
Definition qgssphere.cpp:49
bool isNull() const
Returns true if the sphere is a null (default constructed) sphere.
Definition qgssphere.cpp:34
QgsPoint center() const
Returns the center point of the sphere.
Definition qgssphere.cpp:44
QgsSphere()=default
Constructor for an invalid QgsSphere.
QgsBox3D boundingBox() const
Returns the 3-dimensional bounding box containing the sphere.
Definition qgssphere.cpp:79
double radius() const
Returns the radius of the sphere.
Definition qgssphere.h:140
bool isEmpty() const
Returns true if the sphere is considered empty, i.e.
Definition qgssphere.cpp:39
double volume() const
Returns the volume of the sphere.
Definition qgssphere.cpp:61
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:30
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607