QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
interpolation
Bezier3D.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
Bezier3D.cpp
3
------------
4
copyright : (C) 2004 by Marco Hugentobler
5
email : mhugent@geo.unizh.ch
6
***************************************************************************/
7
8
/***************************************************************************
9
* *
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
14
* *
15
***************************************************************************/
16
17
#include "
Bezier3D.h
"
18
19
#include "
MathUtils.h
"
20
#include "
Vector3D.h
"
21
#include "
qgslogger.h
"
22
23
#include <QString>
24
25
using namespace
Qt::StringLiterals;
26
27
void
Bezier3D::calcFirstDer
(
float
t,
Vector3D
*v )
28
{
29
if
( v &&
mControlPoly
)
30
{
31
v->
setX
( 0 );
32
v->
setY
( 0 );
33
v->
setZ
( 0 );
34
35
if
(
mControlPoly
->count() < 2 )
36
{
37
return
;
38
}
39
40
for
(
int
n = 1; n <= int(
mControlPoly
->count() - 1 ); n++ )
41
{
42
const
double
bernst =
MathUtils::calcBernsteinPoly
(
mControlPoly
->count() - 2, n - 1, t );
43
v->
setX
( v->
getX
() + ( ( *
mControlPoly
)[n]->x() - ( *
mControlPoly
)[n - 1]->x() ) * bernst );
44
v->
setY
( v->
getY
() + ( ( *
mControlPoly
)[n]->y() - ( *
mControlPoly
)[n - 1]->y() ) * bernst );
45
v->
setZ
( v->
getZ
() + ( ( *
mControlPoly
)[n]->z() - ( *
mControlPoly
)[n - 1]->z() ) * bernst );
46
}
47
v->
setX
( v->
getX
() * (
mControlPoly
->count() - 1 ) );
48
v->
setY
( v->
getY
() * (
mControlPoly
->count() - 1 ) );
49
v->
setZ
( v->
getZ
() * (
mControlPoly
->count() - 1 ) );
50
}
51
52
else
53
{
54
QgsDebugError
( u
"warning: null pointer"
_s );
55
}
56
}
57
58
void
Bezier3D::calcPoint
(
float
t,
QgsPoint
*p )
59
{
60
if
( p &&
mControlPoly
)
61
{
62
p->
setX
( 0 );
63
p->
setY
( 0 );
64
p->
setZ
( 0 );
65
66
for
(
int
n = 1; n <= int(
mControlPoly
->count() ); n++ )
67
{
68
const
double
bernst =
MathUtils::calcBernsteinPoly
(
mControlPoly
->count() - 1, n - 1, t );
69
p->
setX
( p->
x
() + ( *
mControlPoly
)[n - 1]->x() * bernst );
70
p->
setY
( p->
y
() + ( *
mControlPoly
)[n - 1]->y() * bernst );
71
p->
setZ
( p->
z
() + ( *
mControlPoly
)[n - 1]->z() * bernst );
72
}
73
}
74
75
else
76
{
77
QgsDebugError
( u
"warning: null pointer"
_s );
78
}
79
}
80
81
void
Bezier3D::calcSecDer
(
float
t,
Vector3D
*v )
82
{
83
if
( v &&
mControlPoly
)
84
{
85
v->
setX
( 0 );
86
v->
setY
( 0 );
87
v->
setZ
( 0 );
88
89
const
int
nodes =
mControlPoly
->count();
90
if
( nodes < 3 )
91
{
92
return
;
93
}
94
95
for
(
int
n = 1; n <= int( nodes - 2 ); n++ )
96
{
97
const
double
bernst =
MathUtils::calcBernsteinPoly
( nodes - 3, n - 1, t );
98
v->
setX
( v->
getX
() + ( ( *
mControlPoly
)[n + 1]->x() - 2 * ( *
mControlPoly
)[n]->x() + ( *
mControlPoly
)[n - 1]->x() ) * bernst );
99
v->
setY
( v->
getY
() + ( ( *
mControlPoly
)[n + 1]->y() - 2 * ( *
mControlPoly
)[n]->y() + ( *
mControlPoly
)[n - 1]->y() ) * bernst );
100
v->
setZ
( v->
getZ
() + ( ( *
mControlPoly
)[n + 1]->z() - 2 * ( *
mControlPoly
)[n]->z() + ( *
mControlPoly
)[n - 1]->z() ) * bernst );
101
}
102
v->
setX
( v->
getX
() *
MathUtils::faculty
( nodes - 1 ) /
MathUtils::faculty
( nodes - 3 ) );
103
v->
setY
( v->
getY
() *
MathUtils::faculty
( nodes - 1 ) /
MathUtils::faculty
( nodes - 3 ) );
104
v->
setZ
( v->
getZ
() *
MathUtils::faculty
( nodes - 1 ) /
MathUtils::faculty
( nodes - 3 ) );
105
}
106
107
else
108
{
109
QgsDebugError
( u
"warning: null pointer"
_s );
110
}
111
}
112
113
114
void
Bezier3D::changeDirection
()
//does this work correctly? more testing is needed.
115
{
116
if
(
mControlPoly
)
117
{
118
QgsPoint
**pointer =
new
QgsPoint
*[
mControlPoly
->count()];
//create an array to temporarily store pointer to the control points
119
for
(
int
i = 0; i <
mControlPoly
->count(); i++ )
//store the points
120
{
121
pointer[i] = ( *mControlPoly )[i];
122
}
123
124
for
(
int
i = 0; i <
mControlPoly
->count(); i++ )
125
{
126
mControlPoly
->insert( i, pointer[(
mControlPoly
->count() - 1 ) - i] );
127
}
128
delete
[] pointer;
129
}
130
131
else
132
{
133
QgsDebugError
( u
"warning: null pointer"
_s );
134
}
135
}
Bezier3D.h
MathUtils.h
Vector3D.h
Bezier3D::calcPoint
void calcPoint(float t, QgsPoint *p) override
Calculates the point on the curve and assigns it to p.
Definition
Bezier3D.cpp:58
Bezier3D::calcFirstDer
void calcFirstDer(float t, Vector3D *v) override
Calculates the first derivative and assigns it to v.
Definition
Bezier3D.cpp:27
Bezier3D::changeDirection
void changeDirection() override
Changes the order of control points.
Definition
Bezier3D.cpp:114
Bezier3D::calcSecDer
void calcSecDer(float t, Vector3D *v) override
Calculates the second derivative and assigns it to v.
Definition
Bezier3D.cpp:81
ParametricLine::mControlPoly
QVector< QgsPoint * > * mControlPoly
MControlPoly stores the points of the control polygon.
Definition
ParametricLine.h:47
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition
qgspoint.h:53
QgsPoint::setY
void setY(double y)
Sets the point's y-coordinate.
Definition
qgspoint.h:387
QgsPoint::setX
void setX(double x)
Sets the point's x-coordinate.
Definition
qgspoint.h:376
QgsPoint::z
double z
Definition
qgspoint.h:58
QgsPoint::x
double x
Definition
qgspoint.h:56
QgsPoint::setZ
void setZ(double z)
Sets the point's z-coordinate.
Definition
qgspoint.h:400
QgsPoint::y
double y
Definition
qgspoint.h:57
Vector3D
Represents a 3D-Vector, capable of storing x, y and z-coordinates in double values.
Definition
Vector3D.h:37
Vector3D::setX
void setX(double x)
Sets the x-component of the vector.
Definition
Vector3D.h:105
Vector3D::getY
double getY() const
Returns the y-component of the vector.
Definition
Vector3D.h:95
Vector3D::getX
double getX() const
Returns the x-component of the vector.
Definition
Vector3D.h:90
Vector3D::setY
void setY(double y)
Sets the y-component of the vector.
Definition
Vector3D.h:110
Vector3D::getZ
double getZ() const
Returns the z-component of the vector.
Definition
Vector3D.h:100
Vector3D::setZ
void setZ(double z)
Sets the z-component of the vector.
Definition
Vector3D.h:115
MathUtils::calcBernsteinPoly
double ANALYSIS_EXPORT calcBernsteinPoly(int n, int i, double t)
Calculates the value of a Bernstein polynomial.
Definition
MathUtils.cpp:121
MathUtils::faculty
int ANALYSIS_EXPORT faculty(int n)
Faculty function.
Definition
MathUtils.cpp:199
qgslogger.h
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
Generated on
for QGIS API Documentation by
1.17.0