Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
10
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
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
45
47 (const QDoubleVector3D &v1, const QDoubleVector3D &v2, const QDoubleVector3D &v3)
48{
49 return crossProduct((v2 - v1), (v3 - v1)).normalized();
50}
51
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
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
69{
70 return qSqrt(xp * xp + yp * yp + zp * zp);
71}
72
73#ifndef QT_NO_DEBUG_STREAM
74
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
88{
89 stream << double(vector.x()) << double(vector.y())
90 << double(vector.z());
91 return stream;
92}
93
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
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
double distanceToLine(const QDoubleVector3D &point, const QDoubleVector3D &direction) const
double distanceToPlane(const QDoubleVector3D &plane, const QDoubleVector3D &normal) const
Q_DECL_CONSTEXPR QDoubleVector3D()
double length() const
static QDoubleVector3D normal(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
QDoubleVector3D normalized() const
static Q_DECL_CONSTEXPR QDoubleVector3D crossProduct(const QDoubleVector3D &v1, const QDoubleVector3D &v2)
direction
Combined button and popup list for selecting options.
QDebug operator<<(QDebug dbg, const QDoubleVector3D &vector)
QDataStream & operator>>(QDataStream &stream, QDoubleVector3D &vector)
EGLStreamKHR stream
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
qfloat16 qSqrt(qfloat16 f)
Definition qfloat16.h:289
GLint GLfloat GLfloat GLfloat v2
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLint GLfloat GLfloat v1
GLint GLfloat GLfloat GLfloat GLfloat v3
GLfloat n
GLint y
GLfloat GLfloat p
[1]
GLenum GLsizei len
QList< int > vector
[14]