31 #include <mt/direction_type.h>
33 #include <mt/exception.h>
140 "Ill-defined plane. Input support point is not contained in the \
141 constructed plane") {}
154 const DirectionType& type = DIRECTED);
160 const DirectionType& type = DIRECTED);
165 const DirectionType& type = DIRECTED);
170 const DirectionType& type = DIRECTED);
176 const DirectionType& type = UNDIRECTED);
187 bool operator==(
const Plane3& P)
const;
188 bool operator!=(
const Plane3& P)
const;
204 Unit3& getNormalRef();
205 const Unit3& getNormalRef()
const;
211 Scalar& getDistOrigRef();
212 const Scalar& getDistOrigRef()
const;
220 DirectionType& getDirectionTypeRef();
221 const DirectionType& getDirectionTypeRef()
const;
249 const DirectionType& type = DIRECTED);
254 const DirectionType& type = DIRECTED);
260 const DirectionType& type = DIRECTED);
267 DirectionType m_dir_type;
287 std::ostream& operator<<(std::ostream& os,
298 Scalar distance(
const Point3& p,
302 Scalar distance(
const Line3& L,
310 m_dir_type(DIRECTED) {}
315 const DirectionType& type) :
324 const DirectionType& type) :
333 const DirectionType& type) :
341 #ifdef MT_USE_BASIC_SCALAR
349 const DirectionType& type) :
357 #ifdef MT_USE_BASIC_SCALAR
366 const DirectionType& type)
374 inline bool Plane3::operator==(
const Plane3& P)
const
379 bool same_normal = (m_normal == P.
getNormal());
382 bool same_dist_orig = (m_dist_orig == P.
getDistOrig());
384 if (same_normal && same_dist_orig)
392 const bool both_directed =
398 same_normal = (m_normal == -P.
getNormal());
399 same_dist_orig = (m_dist_orig == -P.
getDistOrig());
400 equal = (same_normal && same_dist_orig);
407 inline bool Plane3::operator!=(
const Plane3& P)
const
409 return !(*
this == P);
417 return Point3(p - (dot(p, m_normal) + m_dist_orig) * m_normal);
423 return abs((dot(p, m_normal) + m_dist_orig));
435 inline Unit3& Plane3::getNormalRef()
441 inline const Unit3& Plane3::getNormalRef()
const
453 inline Scalar& Plane3::getDistOrigRef()
459 inline const Scalar& Plane3::getDistOrigRef()
const
467 return -(m_dist_orig * m_normal);
477 inline DirectionType& Plane3::getDirectionTypeRef()
483 inline const DirectionType& Plane3::getDirectionTypeRef()
const
498 const Unit3 u(sup2 - sup1);
505 const Scalar dnew = m_dist_orig - d;
506 return Plane3(m_normal, dnew, m_dir_type);
524 m_dist_orig = -dot(m_normal, sup);
536 const DirectionType& type)
546 const DirectionType& type)
557 const DirectionType& type)
577 const Unit3 dir[3] = {(sup2 - sup1),
581 const Vector3 cos_vec(abs(angleCos(dir[0], dir[1])),
582 abs(angleCos(dir[1], dir[2])),
583 abs(angleCos(dir[2], dir[0])));
585 const Scalar max_cos = cos_vec.max();
587 #ifdef MT_USE_BASIC_SCALAR
588 util::Assert(max_cos != 1.0,
589 Exception(
"Ill-defined plane. Input points are collinear"));
594 const size_t min_cos_idx = cos_vec.minAxis();
595 const size_t t1 = ( min_cos_idx % 3) + 1;
596 const size_t t2 = ((min_cos_idx + 1) % 3) + 1;
597 m_normal = cross(dir[t1], dir[t2]);
606 const Point3 p[3] = {sup1,
610 const Vector3 len_p (p[0].length2(),
614 const size_t t = len_p.minAxis();
618 #ifdef MT_USE_BASIC_SCALAR
619 util::Assert(
distance(sup1) == 0.0, BadPlane());
620 util::Assert(
distance(sup2) == 0.0, BadPlane());
621 util::Assert(
distance(sup3) == 0.0, BadPlane());
638 return Plane3(-P.getNormal(),
640 P.getDirectionType());
644 inline std::ostream& operator<<(std::ostream& os,
647 return os <<
"norm: " << P.getNormal() <<
' '
648 <<
"dist: " << P.getDistOrig() <<
" - "
649 << P.getDirectionType();
655 inline Point3
project(
const Point3& p,
662 inline Scalar
distance(
const Point3& p,
665 return P.distance(p);
672 return P.distance(p);
678 #endif // MT_PLANE3_H