glc_plane.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024 #include <QtDebug>
00025 #include "glc_plane.h"
00026
00027 GLC_Plane::GLC_Plane()
00028 {
00029 m_Eq[0]= 0.0;
00030 m_Eq[1]= 0.0;
00031 m_Eq[2]= 0.0;
00032 m_Eq[3]= 0.0;
00033 }
00034
00035 GLC_Plane::GLC_Plane(double a, double b, double c, double d)
00036 {
00037 m_Eq[0]= a;
00038 m_Eq[1]= b;
00039 m_Eq[2]= c;
00040 m_Eq[3]= d;
00041
00042 }
00043
00044 GLC_Plane::GLC_Plane(const GLC_Vector3d& normal, double d)
00045 {
00046 m_Eq[0]= normal.x();
00047 m_Eq[1]= normal.y();
00048 m_Eq[2]= normal.z();
00049 m_Eq[3]= d;
00050 }
00051
00052 GLC_Plane::GLC_Plane(const GLC_Vector3d& normal, const GLC_Point3d& point)
00053 {
00054 m_Eq[0]= normal.x();
00055 m_Eq[1]= normal.y();
00056 m_Eq[2]= normal.z();
00057 m_Eq[3]= -normal * point;
00058 }
00059
00060
00061 GLC_Plane::GLC_Plane(const GLC_Point3d& p1, const GLC_Point3d& p2, const GLC_Point3d& p3)
00062 {
00063 const GLC_Vector3d v1(p2 - p1);
00064 const GLC_Vector3d v2(p3 - p1);
00065 const GLC_Vector3d normal((v1 ^ v2).normalize());
00066 m_Eq[0]= normal.x();
00067 m_Eq[1]= normal.y();
00068 m_Eq[2]= normal.z();
00069 m_Eq[3]= -normal * p1;
00070 }
00071
00072
00073 GLC_Plane::GLC_Plane(const GLC_Plane& plane)
00074 {
00075 memcpy(m_Eq, plane.m_Eq, sizeof(double) * 4);
00076 }
00077
00078
00079 GLC_Plane& GLC_Plane::operator=(const GLC_Plane& p)
00080 {
00081 if ((this != &p) && (*this != p))
00082 {
00083 memcpy(m_Eq, p.m_Eq, sizeof(double) * 4);
00084 }
00085 return *this;
00086 }
00087
00088
00089 GLC_Plane::~GLC_Plane()
00090 {
00091
00092 }
00093
00095
00097
00098
00099 bool GLC_Plane::operator==(GLC_Plane p2) const
00100 {
00101 GLC_Plane p1(*this);
00102 p1.normalize();
00103 p2.normalize();
00104 bool areEqual= qFuzzyCompare(p1.m_Eq[0], p2.m_Eq[0]);
00105 areEqual= areEqual && qFuzzyCompare(p1.m_Eq[1], p2.m_Eq[1]);
00106 areEqual= areEqual && qFuzzyCompare(p1.m_Eq[2], p2.m_Eq[2]);
00107 areEqual= areEqual && qFuzzyCompare(p1.m_Eq[3], p2.m_Eq[3]);
00108
00109 return areEqual;
00110 }
00111
00112 QString GLC_Plane::toString() const
00113 {
00114 return QString::number(m_Eq[0]) + "x + " + QString::number(m_Eq[1]) + "y + " + QString::number(m_Eq[2]) + "z + " + QString::number(m_Eq[3]);
00115 }
00117
00119
00120
00121 void GLC_Plane::normalize()
00122 {
00123 const double invMag= 1.0 / sqrt(m_Eq[0] * m_Eq[0] + m_Eq[1] * m_Eq[1] + m_Eq[2] * m_Eq[2]);
00124
00125 m_Eq[0]= m_Eq[0] * invMag;
00126 m_Eq[1]= m_Eq[1] * invMag;
00127 m_Eq[2]= m_Eq[2] * invMag;
00128 m_Eq[3]= m_Eq[3] * invMag;
00129 }
00130
00131 GLC_Plane& GLC_Plane::setPlane(const GLC_Vector3d& normal, const GLC_Point3d& point)
00132 {
00133 m_Eq[0]= normal.x();
00134 m_Eq[1]= normal.y();
00135 m_Eq[2]= normal.z();
00136 m_Eq[3]= -normal * point;
00137
00138 return *this;
00139 }