diff options
author | Laszlo Papp <lpapp@kde.org> | 2013-03-15 04:54:43 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-15 18:37:51 +0100 |
commit | d8bef6bb2e7523112781ad81e0268fa67b610c3b (patch) | |
tree | c6d56eb8d8648a7a987dd77a166d526a00c5435b /src/gui/math3d | |
parent | 379886d24b9b0a88930dc479db2217c15381814f (diff) |
Add a minor convenience for calculating the distance to a point
Change-Id: I312727bf6858ead6c30fe20bf3abc5afc73a3a14
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/gui/math3d')
-rw-r--r-- | src/gui/math3d/qvector3d.cpp | 13 | ||||
-rw-r--r-- | src/gui/math3d/qvector3d.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp index b3bf292f9b..5537562b61 100644 --- a/src/gui/math3d/qvector3d.cpp +++ b/src/gui/math3d/qvector3d.cpp @@ -348,6 +348,19 @@ QVector3D QVector3D::normal } /*! + \since 5.1 + + Returns the distance from this vertex to a point defined by + the vertex \a point. + + \sa distanceToPlane(), distanceToLine() +*/ +float QVector3D::distanceToPoint(const QVector3D& point) const +{ + return (*this - point).length(); +} + +/*! Returns the distance from this vertex to a plane defined by the vertex \a plane and a \a normal unit vector. The \a normal parameter is assumed to have been normalized to a unit vector. diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h index 879b2125ea..49d9ca6bf8 100644 --- a/src/gui/math3d/qvector3d.h +++ b/src/gui/math3d/qvector3d.h @@ -97,6 +97,7 @@ public: static QVector3D normal (const QVector3D& v1, const QVector3D& v2, const QVector3D& v3); + float distanceToPoint(const QVector3D& point) const; float distanceToPlane(const QVector3D& plane, const QVector3D& normal) const; float distanceToPlane(const QVector3D& plane1, const QVector3D& plane2, const QVector3D& plane3) const; float distanceToLine(const QVector3D& point, const QVector3D& direction) const; |