GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_plane.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
23 
24 #include <QtDebug>
25 #include "glc_plane.h"
26 #include "glc_geomtools.h"
27 
29 {
30  m_Eq[0]= 0.0;
31  m_Eq[1]= 0.0;
32  m_Eq[2]= 0.0;
33  m_Eq[3]= 0.0;
34 }
35 
36 GLC_Plane::GLC_Plane(double a, double b, double c, double d)
37 {
38  m_Eq[0]= a;
39  m_Eq[1]= b;
40  m_Eq[2]= c;
41  m_Eq[3]= d;
42 
43 }
44 
45 GLC_Plane::GLC_Plane(const GLC_Vector3d& normal, double d)
46 {
47  m_Eq[0]= normal.x();
48  m_Eq[1]= normal.y();
49  m_Eq[2]= normal.z();
50  m_Eq[3]= d;
51 }
52 
53 GLC_Plane::GLC_Plane(const GLC_Vector3d& normal, const GLC_Point3d& point)
54 {
55  m_Eq[0]= normal.x();
56  m_Eq[1]= normal.y();
57  m_Eq[2]= normal.z();
58  m_Eq[3]= -normal * point;
59 }
60 
61 
62 GLC_Plane::GLC_Plane(const GLC_Point3d& p1, const GLC_Point3d& p2, const GLC_Point3d& p3)
63 {
64  const GLC_Vector3d v1(p2 - p1);
65  const GLC_Vector3d v2(p3 - p1);
66  const GLC_Vector3d normal((v1 ^ v2).normalize());
67  m_Eq[0]= normal.x();
68  m_Eq[1]= normal.y();
69  m_Eq[2]= normal.z();
70  m_Eq[3]= -normal * p1;
71 }
72 
73 
75 {
76  memcpy(m_Eq, plane.m_Eq, sizeof(double) * 4);
77 }
78 
79 
81 {
82  if ((this != &p) && (*this != p))
83  {
84  memcpy(m_Eq, p.m_Eq, sizeof(double) * 4);
85  }
86  return *this;
87 }
88 
89 
91 {
92 
93 }
94 
96 // Get Functions
98 
99 
101 {
102  GLC_Plane p1(*this);
103  p1.normalize();
104  p2.normalize();
105 
106  bool areEqual= glc::compare(p1.m_Eq[0], p2.m_Eq[0], glc::EPSILON);
107  areEqual= areEqual && glc::compare(p1.m_Eq[1], p2.m_Eq[1], glc::EPSILON);
108  areEqual= areEqual && glc::compare(p1.m_Eq[2], p2.m_Eq[2], glc::EPSILON);
109  areEqual= areEqual && glc::compare(p1.m_Eq[3], p2.m_Eq[3], glc::EPSILON);
110 
111  return areEqual;
112 }
113 
115 {
116  const double value= (m_Eq[0] * p.x() + m_Eq[1] * p.y() + m_Eq[2] * p.z() + m_Eq[3]);
117  bool subject = glc::compare(value, 0.0, glc::EPSILON);
118 
119  return subject;
120 }
121 
122 QString GLC_Plane::toString() const
123 {
124  return QString::number(m_Eq[0]) + "x + " + QString::number(m_Eq[1]) + "y + " + QString::number(m_Eq[2]) + "z + " + QString::number(m_Eq[3]);
125 }
127 // Set Functions
129 
130 // Normalize the plane
132 {
133  const double invMag= 1.0 / sqrt(m_Eq[0] * m_Eq[0] + m_Eq[1] * m_Eq[1] + m_Eq[2] * m_Eq[2]);
134 
135  m_Eq[0]= m_Eq[0] * invMag;
136  m_Eq[1]= m_Eq[1] * invMag;
137  m_Eq[2]= m_Eq[2] * invMag;
138  m_Eq[3]= m_Eq[3] * invMag;
139 }
140 
142 {
143  m_Eq[0]= normal.x();
144  m_Eq[1]= normal.y();
145  m_Eq[2]= normal.z();
146  m_Eq[3]= -normal * point;
147 
148  return *this;
149 }
150 
152 {
153  m_Eq[0]= normal.x();
154  m_Eq[1]= normal.y();
155  m_Eq[2]= normal.z();
156 
157  return *this;
158 }

©2005-2013 Laurent Ribon