Loading...
Searching...
No Matches
plane3.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_MATHS_PLANE3_H
#define BALL_MATHS_PLANE3_H
#ifdef BALL_HAS_IEEEFP_H
# include <ieeefp.h>
#endif
#include <cmath>
#include <iostream>
#ifndef BALL_MATHS_LINE3_H
# include <BALL/MATHS/line3.h>
#endif
#ifndef BALL_MATHS_VECTOR3_H
# include <BALL/MATHS/vector3.h>
#endif
#ifndef BALL_MATHS_COMMON_H
# include <BALL/MATHS/common.h>
#endif
namespace BALL
{
template <typename T>
class TPlane3;
template <typename T>
std::istream& operator >> (std::istream& s, TPlane3<T>& plane);
template <typename T>
std::ostream& operator << (std::ostream& s, const TPlane3<T>& plane);
template <typename T>
class TPlane3
{
public:
BALL_CREATE(TPlane3<T>)
TPlane3()
: p(),
n()
{
}
TPlane3(const TPlane3& plane)
: p(plane.p),
n(plane.n)
{
}
TPlane3(const TVector3<T>& point, const TVector3<T>& normal)
: p(point),
n(normal)
{
}
TPlane3(const TVector3<T>& a, const TVector3<T>& b, const TVector3<T>& c)
: p(a),
n((a - b) % (b - c))
{
}
TPlane3(const T& a, const T& b, const T& c, const T& d)
{
n = TVector3<T>(a, b, c);
if (a == 0 && b == 0 && c == 0)
{
throw Exception::DivisionByZero(__FILE__, __LINE__);
}
if (!Maths::isZero(a))
{
p.set(-d / a, 0, 0);
}
else if (!Maths::isZero(b))
{
p.set(0, -d / b, 0);
}
else if (!Maths::isZero(c))
{
p.set(0, 0, -d / c);
}
}
virtual ~TPlane3()
{
}
virtual void clear()
{
n.clear();
p.clear();
}
void swap(TPlane3& plane)
{
TVector3<T> temp_point(p);
p = plane.p;
plane.p = temp_point;
temp_point = n;
n = plane.n;
plane.n = temp_point;
}
void set(const TPlane3& plane)
{
p = plane.p;
n = plane.n;
}
void set(const TVector3<T>& point, const TVector3<T>& normal)
{
p = point;
n = normal;
}
void set(const TVector3<T>& a, const TVector3<T>& b, const TVector3<T>& c)
{
p = a;
n = (a - b) % (b - c);
}
TPlane3& operator = (const TPlane3& plane)
{
p = plane.p;
n = plane.n;
return *this;
}
void get(TPlane3& plane) const
{
plane.p = p;
plane.n = n;
}
void get(TVector3<T>& point, TVector3<T>& normal) const
{
point = p;
normal = n;
}
void normalize()
{
T length = n.getLength();
// throw an exception on zero length normal
if (length == 0.0)
{
throw Exception::DivisionByZero(__FILE__, __LINE__);
}
n /= length;
}
void hessify()
{
normalize();
if (Maths::isLess(n * p, 0))
{
n.negate();
}
}
bool operator == (const TPlane3& plane) const
{
return (p == plane.p && n == plane.n);
}
bool operator != (const TPlane3& plane) const
{
return (p != plane.p || n != plane.n);
}
bool has(const TVector3<T>& point) const
{
return Maths::isZero(n * (point - p));
}
bool has(const TLine3<T>& line) const
{
return (Maths::isZero(n * line.d) && has(line.p));
}
bool isValid() const
{
return true;
}
void dump(std::ostream& s = std::cout, Size depth = 0) const
{
BALL_DUMP_STREAM_PREFIX(s);
BALL_DUMP_HEADER(s, this, this);
BALL_DUMP_DEPTH(s, depth);
s << " position: " << p << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << " normal: " << n << std::endl;
BALL_DUMP_STREAM_SUFFIX(s);
}
TVector3<T> p;
TVector3<T> n;
};
template <typename T>
std::istream& operator >> (std::istream& s, TPlane3<T>& plane)
{
char c;
s >> c >> plane.p >> plane.n >> c;
return s;
}
template <typename T>
std::ostream& operator << (std::ostream& s, const TPlane3<T>& plane)
{
return (s << '(' << plane.p << ' ' << plane.n << ')');
}
typedef TPlane3<float> Plane3;
} // namespace BALL
#endif // BALL_MATHS_PLANE3_H
common.h
BALL::Exception::DivisionByZero
Definition COMMON/exception.h:342
BALL::TLine3
Definition line3.h:47
BALL::TLine3::p
TVector3< T > p
Definition line3.h:347
BALL::TLine3::d
TVector3< T > d
Definition line3.h:351
BALL::TPlane3
Definition plane3.h:53
BALL::TPlane3::TPlane3
TPlane3(const TVector3< T > &point, const TVector3< T > &normal)
Definition plane3.h:89
BALL::TPlane3::isValid
bool isValid() const
Definition plane3.h:332
BALL::TPlane3::TPlane3
TPlane3(const TVector3< T > &a, const TVector3< T > &b, const TVector3< T > &c)
Definition plane3.h:101
BALL::TPlane3::TPlane3
TPlane3(const TPlane3 &plane)
Definition plane3.h:77
BALL::TPlane3::has
bool has(const TVector3< T > &point) const
Definition plane3.h:307
BALL::TPlane3::normalize
void normalize()
Definition plane3.h:251
BALL::TPlane3::get
void get(TVector3< T > &point, TVector3< T > &normal) const
Definition plane3.h:234
BALL::TPlane3< float >::p
TVector3< float > p
Definition plane3.h:366
BALL::TPlane3::operator==
bool operator==(const TPlane3 &plane) const
Definition plane3.h:288
BALL::TPlane3::set
void set(const TVector3< T > &a, const TVector3< T > &b, const TVector3< T > &c)
Definition plane3.h:199
BALL::TPlane3::has
bool has(const TLine3< T > &line) const
Definition plane3.h:317
BALL::TPlane3::clear
virtual void clear()
Definition plane3.h:147
BALL::TPlane3::swap
void swap(TPlane3 &plane)
Definition plane3.h:161
BALL::TPlane3::TPlane3
TPlane3(const T &a, const T &b, const T &c, const T &d)
Definition plane3.h:114
BALL::TPlane3::operator=
TPlane3 & operator=(const TPlane3 &plane)
Definition plane3.h:210
BALL::TPlane3< float >::n
TVector3< float > n
Definition plane3.h:370
BALL::TPlane3::~TPlane3
virtual ~TPlane3()
Definition plane3.h:139
BALL::TPlane3::dump
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition plane3.h:344
BALL::TPlane3::set
void set(const TVector3< T > &point, const TVector3< T > &normal)
Definition plane3.h:187
BALL::TPlane3::get
void get(TPlane3 &plane) const
Definition plane3.h:223
BALL::TPlane3::set
void set(const TPlane3 &plane)
Definition plane3.h:176
BALL::TPlane3::hessify
void hessify()
Definition plane3.h:269
BALL::TPlane3::TPlane3
TPlane3()
Definition plane3.h:66
BALL::TPlane3::operator!=
bool operator!=(const TPlane3 &plane) const
Definition plane3.h:297
BALL::TVector3
Definition vector3.h:71
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL::Plane3
TPlane3< float > Plane3
Definition plane3.h:401
BALL::operator<<
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
line3.h
BALL_DUMP_STREAM_PREFIX
#define BALL_DUMP_STREAM_PREFIX(os)
Definition macros.h:391
BALL_DUMP_STREAM_SUFFIX
#define BALL_DUMP_STREAM_SUFFIX(os)
Definition macros.h:395
BALL_DUMP_DEPTH
#define BALL_DUMP_DEPTH(os, depth)
Definition macros.h:390
BALL_DUMP_HEADER
#define BALL_DUMP_HEADER(os, cl, ob)
Definition macros.h:393
BALL::Maths::isLess
bool isLess(const T1 &a, const T2 &b)
Definition MATHS/common.h:236
BALL::Maths::isZero
bool isZero(const T &t)
Definition MATHS/common.h:189
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::operator>>
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
Definition regularData1D.h:802
vector3.h