2 #ifndef vgl_plane_3d_hxx_ 3 #define vgl_plane_3d_hxx_ 19 # include <vcl_msvc_warnings.h> 26 : a_(p.a()), b_(p.b()), c_(p.c()), d_(p.d()) {assert (
a_||
b_||
c_);}
33 : a_(p2.y()*p3.z()-p2.z()*p3.y()
34 +p3.y()*p1.z()-p3.z()*p1.y()
35 +p1.y()*p2.z()-p1.z()*p2.y())
36 , b_(p2.z()*p3.x()-p2.x()*p3.z()
37 +p3.z()*p1.x()-p3.x()*p1.z()
38 +p1.z()*p2.x()-p1.x()*p2.z())
39 , c_(p2.x()*p3.y()-p2.y()*p3.x()
40 +p3.x()*p1.y()-p3.y()*p1.x()
41 +p1.x()*p2.y()-p1.y()*p2.x())
42 , d_(p1.x()*(p2.z()*p3.y()-p2.y()*p3.z())
43 +p2.x()*(p3.z()*p1.y()-p3.y()*p1.z())
44 +p3.x()*(p1.z()*p2.y()-p1.y()*p2.z()))
53 : a_(n.x()), b_(n.y()), c_(n.z()), d_(-(n.x()*p.x()+n.y()*p.y()+n.z()*p.z()))
64 double para = std::fabs(1.0-std::fabs(
cos_angle(v0, v1)));
65 bool parallel = para < vgl_tolerance<double>::position;
69 double d01 =
length(p1-p0);
70 bool coincident = d01 < vgl_tolerance<double>::position;
83 a_=pln.
a(); b_=pln.
b(); c_=pln.
c(); d_=pln.
d();
90 a_=pln.
a(); b_=pln.
b(); c_=pln.
c(); d_=pln.
d();
94 double sum = a_*a_ + b_*b_ + c_*c_;
97 double den = std::sqrt(sum);
98 double an= (double)a()/den; a_ = (T)an;
99 double bn= (double)b()/den; b_ = (T)bn;
100 double cn= (double)c()/den; c_ = (T)cn;
101 double dn= (double)d()/den; d_ = (T)dn;
103 if ((std::fabs(an)>=std::fabs(bn) && std::fabs(an)>=std::fabs(cn) && an < 0) ||
104 (std::fabs(bn)>std::fabs(an) && std::fabs(bn)>=std::fabs(cn) && bn < 0) ||
105 (std::fabs(cn)>std::fabs(an) && std::fabs(cn)>std::fabs(bn) && cn < 0))
106 a_ = -a_, b_ = -b_, c_ = -c_, d_ = -d_;
116 return dist >= -tol && dist <= tol;
123 ( (a()*p.
b()==p.
a()*b())
124 && (a()*p.
c()==p.
a()*c())
125 && (a()*p.
d()==p.
a()*d())
126 && (b()*p.
c()==p.
b()*c())
127 && (b()*p.
d()==p.
b()*d())
128 && (c()*p.
d()==p.
c()*d()) );
131 #define vp(os,v,s) os<<' '<< v << ' ' <<s; 136 os <<
"<vgl_plane_3d";
vp(os,p.
a(),
"x");
vp(os,p.
b(),
"y");
vp(os,p.
c(),
"z");
137 vp(os,p.
d(),
"");
return os <<
" = 0 >";
145 if (! is.good())
return is;
147 bool formatted =
false;
158 if (is.eof())
return is;
159 if (is.peek() ==
'(') { is.ignore(); paren=
true; }
160 is >> std::ws >> a >> std::ws;
161 if (is.eof())
return is;
162 if (is.peek() ==
',') is.ignore();
163 else if (is.peek() ==
'x') { is.ignore(); formatted=
true; }
164 is >> std::ws >> b >> std::ws;
165 if (is.eof())
return is;
167 if (is.eof())
return is;
168 if (is.peek() ==
'y') is.ignore();
171 else if (is.peek() ==
',') is.ignore();
172 is >> std::ws >> c >> std::ws;
173 if (is.eof())
return is;
175 if (is.eof())
return is;
176 if (is.peek() ==
'z') is.ignore();
179 else if (is.peek() ==
',') is.ignore();
180 is >> std::ws >> d >> std::ws;
182 if (is.eof())
return is;
183 if (is.peek() ==
')') is.ignore();
187 if (is.eof())
return is;
188 if (is.peek() ==
'=') is.ignore();
191 if (is.peek() ==
'0') is.ignore();
194 if (!paren && is.peek() ==
'>') is.ignore();
211 T dp = (T)1 - (T)std::fabs(static_cast<double>(
dot_product(n, Y)));
212 T tol = ((T)1)/((T)10);
231 double dist =
vgl_distance(p3d, pt_on_plane), dtol = static_cast<double>(tol);
239 this->plane_coord_vectors(uvec, vvec);
251 this->plane_coord_vectors(uvec, vvec);
256 #undef VGL_PLANE_3D_INSTANTIATE 257 #define VGL_PLANE_3D_INSTANTIATE(T) \ 258 template class vgl_plane_3d<T >; \ 259 template std::ostream& operator<<(std::ostream&, vgl_plane_3d<T >const&); \ 260 template std::istream& operator>>(std::istream&, vgl_plane_3d<T >&) 262 #endif // vgl_plane_3d_hxx_
homogeneous plane in 3D projective space
v normalized(v const &a)
Return a normalised version of a.
T dot_product(v const &a, v const &b)
dot product or inner product of two vectors.
a point in 2D nonhomogeneous space
T a() const
Return x coefficient.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
A 3-d ray defined by an origin and a direction vector.
double length(v const &a)
Return the length of a vector.
void plane_coord_vectors(vgl_vector_3d< T > &uvec, vgl_vector_3d< T > &vvec) const
plane coordinate unit vectors.
Set of closest-point functions.
vgl_point_2d< T > vgl_closest_point_origin(vgl_line_2d< T > const &l)
Return the point on the given line closest to the origin.
T b() const
Return y coefficient.
a point in 3D nonhomogeneous space
vgl_point_2d< T > vgl_closest_point(vgl_line_2d< T > const &l, vgl_point_2d< T > const &p)
Return the point on the given line closest to the given point.
void set(Type px, Type py)
Set x and y.
T cross_product(v const &a, v const &b)
cross product of two vectors (area of enclosed parallellogram).
bool plane_coords(vgl_point_3d< T > const &p3d, vgl_point_2d< T > &p2d, T tol=(T) 0) const
Given a 3-d point, return a 2-d point in the coord. system of the plane.
Represents a Euclidean 3D plane.
T d() const
Return constant coefficient.
vgl_point_3d< Type > origin() const
Accessors.
Direction vector in Euclidean 3D space, templated by type of element.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
double vgl_distance(vgl_point_2d< T >const &p1, vgl_point_2d< T >const &p2)
return the distance between two points.
void set(T ta, T tb, T tc, T td)
Set this vgl_plane_3d to have the equation $ax+by+cz+d=0$.
a plane in 3D nonhomogeneous space
vgl_point_3d< T > world_coords(vgl_point_2d< T > const &p2d) const
inverse map from plane coordinates to world coordinates.
bool operator==(vgl_plane_3d< T > const &p) const
the comparison operator.
bool parallel(v const &a, v const &b, double eps=0.0)
are two vectors parallel, i.e., is one a scalar multiple of the other?.
Set of distance functions.
double cos_angle(v const &a, v const &b)
cosine of the angle between two vectors.
bool contains(vgl_point_3d< T > const &p, T tol=(T) 0) const
Return true if p is on the plane.
vgl_vector_3d< Type > direction() const
T c() const
Return z coefficient.