49 lines
1.0 KiB
C++
Executable File
49 lines
1.0 KiB
C++
Executable File
|
|
|
|
|
|
#include "qpoint3d.h"
|
|
#include <QDataStream>
|
|
|
|
using namespace LtsUtils;
|
|
|
|
|
|
double QPoint3D::distanceToLine(const QPoint3D &point, const QPoint3D &direction) const
|
|
{
|
|
if (direction.isNull())
|
|
return (*this - point).length();
|
|
QPoint3D p = point + dotProduct(*this - point, direction) * direction;
|
|
return (*this - p).length();
|
|
}
|
|
|
|
double QPoint3D::distanceToPlane(const QPoint3D &plane, const QPoint3D &normal) const
|
|
{
|
|
return dotProduct(*this - plane, normal);
|
|
}
|
|
|
|
double QPoint3D::distanceToPlane(const QPoint3D &plane1, const QPoint3D &plane2, const QPoint3D &plane3) const
|
|
{
|
|
QPoint3D n = normal(plane2 - plane1, plane3 - plane1);
|
|
return dotProduct(*this - plane1, n);
|
|
}
|
|
|
|
double QPoint3D::distanceToPoint(const QPoint3D &point) const
|
|
{
|
|
return (*this - point).length();
|
|
}
|
|
|
|
|
|
QDataStream &operator<<(QDataStream &s, const QPoint3D &p)
|
|
{
|
|
s << p.x() << p.y() << p.z();
|
|
return s;
|
|
}
|
|
|
|
QDataStream &operator>>(QDataStream &s, QPoint3D &p)
|
|
{
|
|
double x, y, z;
|
|
s >> x; p.rx() = x;
|
|
s >> y; p.ry() = y;
|
|
s >> z; p.rz() = z;
|
|
return s;
|
|
}
|