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