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
5#include <QtCore/qdatastream.h>
6#include <QtCore/qmath.h>
7#include <QtCore/qdebug.h>
8
10
11QDoubleVector3D QDoubleVector3D::normalized() const
12{
13 const double len = length();
14 if (qFuzzyIsNull(len - 1.0))
15 return *this;
16 else if (!qFuzzyIsNull(len))
17 return *this / len;
18 else
19 return QDoubleVector3D();
20}
21
22void QDoubleVector3D::normalize()
23{
24 double len = length();
25 if (qFuzzyIsNull(len) || qFuzzyIsNull(len - 1.0))
26 return;
27
28 xp /= len;
29 yp /= len;
30 zp /= len;
31}
32
33QDoubleVector3D QDoubleVector3D::normal(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
34{
35 return crossProduct(v1, v2).normalized();
36}
37
38QDoubleVector3D QDoubleVector3D::normal
39 (const QDoubleVector3D &v1, const QDoubleVector3D &v2, const QDoubleVector3D &v3)
40{
41 return crossProduct((v2 - v1), (v3 - v1)).normalized();
42}
43
44double QDoubleVector3D::distanceToPlane
45 (const QDoubleVector3D &plane1, const QDoubleVector3D &plane2, const QDoubleVector3D &plane3) const
46{
47 QDoubleVector3D n = normal(plane2 - plane1, plane3 - plane1);
48 return dotProduct(*this - plane1, n);
49}
50
51double QDoubleVector3D::distanceToLine
52 (const QDoubleVector3D &point, const QDoubleVector3D &direction) const
53{
54 if (direction.isNull())
55 return (*this - point).length();
56 QDoubleVector3D p = point + dotProduct(*this - point, direction) * direction;
57 return (*this - p).length();
58}
59
60double QDoubleVector3D::length() const
61{
62 return qHypot(xp, yp, zp);
63}
64
65#ifndef QT_NO_DEBUG_STREAM
66
67QDebug operator<<(QDebug dbg, const QDoubleVector3D &vector)
68{
69 QDebugStateSaver saver(dbg);
70 dbg.nospace() << "QDoubleVector3D("
71 << vector.x() << ", " << vector.y() << ", " << vector.z() << ')';
72 return dbg;
73}
74
75#endif
76
77#ifndef QT_NO_DATASTREAM
78
79QDataStream &operator<<(QDataStream &stream, const QDoubleVector3D &vector)
80{
81 stream << double(vector.x()) << double(vector.y())
82 << double(vector.z());
83 return stream;
84}
85
86QDataStream &operator>>(QDataStream &stream, QDoubleVector3D &vector)
87{
88 double x, y, z;
89 stream >> x;
90 stream >> y;
91 stream >> z;
92 vector.setX(double(x));
93 vector.setY(double(y));
94 vector.setZ(double(z));
95 return stream;
96}
97
98#endif // QT_NO_DATASTREAM
99
100QT_END_NAMESPACE
Combined button and popup list for selecting options.
QDataStream & operator<<(QDataStream &stream, const QDoubleVector3D &vector)
QDebug operator<<(QDebug dbg, const QDoubleVector3D &vector)
QDataStream & operator>>(QDataStream &stream, QDoubleVector3D &vector)