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