Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdoublevector3d.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qdoublevector3d_p.h"
5
#
include
<
QtCore
/
qdatastream
.
h
>
6
#
include
<
QtCore
/
qmath
.
h
>
7
#
include
<
QtCore
/
qdebug
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
QDoubleVector3D QDoubleVector3D::normalized()
const
12
{
13
// Need some extra precision if the length is very small.
14
double
len =
double
(xp) *
double
(xp) +
15
double
(yp) *
double
(yp) +
16
double
(zp) *
double
(zp);
17
if
(qFuzzyIsNull(len - 1.0))
18
return
*
this
;
19
else
if
(!qFuzzyIsNull(len))
20
return
*
this
/ (
double
)qSqrt(len);
21
else
22
return
QDoubleVector3D();
23
}
24
25
void
QDoubleVector3D::normalize()
26
{
27
// Need some extra precision if the length is very small.
28
double
len =
double
(xp) *
double
(xp) +
29
double
(yp) *
double
(yp) +
30
double
(zp) *
double
(zp);
31
if
(qFuzzyIsNull(len - 1.0) || qFuzzyIsNull(len))
32
return
;
33
34
len = qSqrt(len);
35
36
xp /= len;
37
yp /= len;
38
zp /= len;
39
}
40
41
QDoubleVector3D QDoubleVector3D::normal(
const
QDoubleVector3D &v1,
const
QDoubleVector3D &v2)
42
{
43
return
crossProduct(v1, v2).normalized();
44
}
45
46
QDoubleVector3D QDoubleVector3D::normal
47
(
const
QDoubleVector3D &v1,
const
QDoubleVector3D &v2,
const
QDoubleVector3D &v3)
48
{
49
return
crossProduct((v2 - v1), (v3 - v1)).normalized();
50
}
51
52
double
QDoubleVector3D::distanceToPlane
53
(
const
QDoubleVector3D &plane1,
const
QDoubleVector3D &plane2,
const
QDoubleVector3D &plane3)
const
54
{
55
QDoubleVector3D n = normal(plane2 - plane1, plane3 - plane1);
56
return
dotProduct(*
this
- plane1, n);
57
}
58
59
double
QDoubleVector3D::distanceToLine
60
(
const
QDoubleVector3D &point,
const
QDoubleVector3D &direction)
const
61
{
62
if
(direction.isNull())
63
return
(*
this
- point).length();
64
QDoubleVector3D p = point + dotProduct(*
this
- point, direction) * direction;
65
return
(*
this
- p).length();
66
}
67
68
double
QDoubleVector3D::length()
const
69
{
70
return
qSqrt(xp * xp + yp * yp + zp * zp);
71
}
72
73
#
ifndef
QT_NO_DEBUG_STREAM
74
75
QDebug
operator
<<(QDebug dbg,
const
QDoubleVector3D &vector)
76
{
77
QDebugStateSaver saver(dbg);
78
dbg.nospace() <<
"QDoubleVector3D("
79
<< vector.x() <<
", "
<< vector.y() <<
", "
<< vector.z() <<
')'
;
80
return
dbg;
81
}
82
83
#
endif
84
85
#
ifndef
QT_NO_DATASTREAM
86
87
QDataStream
&
operator
<<(QDataStream &stream,
const
QDoubleVector3D &vector)
88
{
89
stream <<
double
(vector.x()) <<
double
(vector.y())
90
<<
double
(vector.z());
91
return
stream;
92
}
93
94
QDataStream
&
operator
>>(QDataStream &stream, QDoubleVector3D &vector)
95
{
96
double
x, y, z;
97
stream >> x;
98
stream >> y;
99
stream >> z;
100
vector.setX(
double
(x));
101
vector.setY(
double
(y));
102
vector.setZ(
double
(z));
103
return
stream;
104
}
105
106
#
endif
// QT_NO_DATASTREAM
107
108
QT_END_NAMESPACE
QPlatformGraphicsBufferHelper
\inmodule QtGui
operator<<
QDataStream & operator<<(QDataStream &stream, const QDoubleVector3D &vector)
Definition
qdoublevector3d.cpp:87
operator<<
QDebug operator<<(QDebug dbg, const QDoubleVector3D &vector)
Definition
qdoublevector3d.cpp:75
operator>>
QDataStream & operator>>(QDataStream &stream, QDoubleVector3D &vector)
Definition
qdoublevector3d.cpp:94
qtpositioning
src
positioning
qdoublevector3d.cpp
Generated on
for Qt by
1.14.0