Loading...
Searching...
No Matches
line3.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: line3.h,v 1.48 2004/07/05 20:57:28 oliver Exp $
//
#ifndef BALL_MATHS_LINE3_H
#define BALL_MATHS_LINE3_H
#ifndef BALL_COMMON_EXCEPTION_H
# include <BALL/COMMON/exception.h>
#endif
#ifndef BALL_MATHS_VECTOR3_H
# include <BALL/MATHS/vector3.h>
#endif
namespace BALL
{
template <typename T>
class TLine3;
template <typename T>
std::ostream& operator << (std::ostream& s, const TLine3<T>& line)
;
template <typename T>
std::istream& operator >> (std::istream& s, TLine3<T>& line)
;
template <typename T>
class TLine3
{
public:
BALL_CREATE(TLine3<T>)
enum Form
{
FORM__PARAMETER = 0,
FORM__TWO_POINTS = 1
};
TLine3()
: p(),
d()
{
}
TLine3(const TLine3& line)
: p(line.p),
d(line.d)
{
}
// form: PARAMETER (default) or TWO_POINTS
TLine3(const TVector3<T>& point, const TVector3<T>& vector, Form form = FORM__PARAMETER)
: p(point),
d((form == FORM__PARAMETER)
? vector
: vector - point)
{
}
virtual ~TLine3()
{
}
virtual void clear()
{
p.clear();
d.clear();
}
void swap(TLine3& line)
{
TVector3<T> temp_point(p);
p = line.p;
line.p = temp_point;
TVector3<T> temp_vector(d);
d = line.d;
line.d = temp_vector;
}
void set(const TLine3& line)
{
p = line.p;
d = line.d;
}
void set(const TVector3<T>& point, const TVector3<T>& vector, Form form = FORM__PARAMETER)
{
p = point;
if (form == FORM__PARAMETER)
{
d = vector;
}
else
{
d = vector - point;
}
}
TLine3& operator = (const TLine3& line)
{
p = line.p;
d = line.d;
return *this;
}
void get(TLine3& line) const
{
line.p = p;
line.d = d;
}
void get(TVector3<T>& point,TVector3<T>& vector, Form form = FORM__PARAMETER) const
{
point = p;
if (form == FORM__PARAMETER)
{
vector = d;
}
else
{
vector - point = d;
}
}
void normalize()
{
d.normalize();
}
bool operator == (const TLine3& line) const
{
return (p == line.p && d == line.d);
}
bool operator != (const TLine3& line) const
{
return (p != line.p || d != line.d);
}
bool has(const TVector3<T>& point) const
{
if (Maths::isNotZero(d.x))
{
T c = (point.x - p.x) / d.x;
return (Maths::isEqual(p.y + c * d.y, point.y) && Maths::isEqual(p.z + c * d.z, point.z));
}
else
{
if (Maths::isNotZero(d.y))
{
T c = (point.y - p.y) / d.y;
return (Maths::isEqual(p.x, point.x) // invariant: d.x == 0
&& Maths::isEqual(p.z + c * d.z, point.z));
}
else
{
if (Maths::isNotZero(d.z))
{
return (Maths::isEqual(p.x, point.x) // invariant: d.x == 0
&& Maths::isEqual(p.y, point.y)); // invariant: d.y == 0
}
else
{
return false;
}
}
}
}
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 << " direction: " << d << std::endl;
BALL_DUMP_STREAM_SUFFIX(s);
}
TVector3<T> p;
TVector3<T> d;
};
typedef TLine3<float> Line3;
template <typename T>
std::istream& operator >> (std::istream& s, TLine3<T>& line)
{
char c;
s >> c >> line.p >> line.d >> c;
return s;
}
template <typename T>
std::ostream& operator << (std::ostream& s, const TLine3<T>& line)
{
s << '(' << line.p << ' ' << line.d << ')';
return s;
}
} // namespace BALL
#endif // BALL_MATHS_LINE3_H
exception.h
BALL::TLine3
Definition line3.h:47
BALL::TLine3::TLine3
TLine3(const TLine3 &line)
Definition line3.h:84
BALL::TLine3< float >::p
TVector3< float > p
Definition line3.h:347
BALL::TLine3::set
void set(const TVector3< T > &point, const TVector3< T > &vector, Form form=FORM__PARAMETER)
Definition line3.h:167
BALL::TLine3::get
void get(TLine3 &line) const
Definition line3.h:198
BALL::TLine3::set
void set(const TLine3 &line)
Definition line3.h:154
BALL::TLine3::TLine3
TLine3(const TVector3< T > &point, const TVector3< T > &vector, Form form=FORM__PARAMETER)
Definition line3.h:102
BALL::TLine3::operator!=
bool operator!=(const TLine3 &line) const
Definition line3.h:260
BALL::TLine3::TLine3
TLine3()
Definition line3.h:73
BALL::TLine3::operator==
bool operator==(const TLine3 &line) const
Definition line3.h:251
BALL::TLine3::dump
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition line3.h:323
BALL::TLine3::Form
Form
Definition line3.h:61
BALL::TLine3< float >::FORM__PARAMETER
@ FORM__PARAMETER
Definition line3.h:62
BALL::TLine3< float >::FORM__TWO_POINTS
@ FORM__TWO_POINTS
Definition line3.h:63
BALL::TLine3::has
bool has(const TVector3< T > &point) const
Definition line3.h:269
BALL::TLine3::~TLine3
virtual ~TLine3()
Definition line3.h:115
BALL::TLine3< float >::d
TVector3< float > d
Definition line3.h:351
BALL::TLine3::swap
void swap(TLine3 &line)
Definition line3.h:139
BALL::TLine3::isValid
bool isValid() const
Definition line3.h:311
BALL::TLine3::normalize
void normalize()
Definition line3.h:237
BALL::TLine3::get
void get(TVector3< T > &point, TVector3< T > &vector, Form form=FORM__PARAMETER) const
Definition line3.h:212
BALL::TLine3::clear
virtual void clear()
Definition line3.h:123
BALL::TLine3::operator=
TLine3 & operator=(const TLine3 &line)
Definition line3.h:185
BALL::TVector3
Definition vector3.h:71
BALL::TVector3::x
T x
Definition vector3.h:489
BALL::TVector3::y
T y
Definition vector3.h:493
BALL::TVector3::z
T z
Definition vector3.h:497
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL::Line3
TLine3< float > Line3
Definition line3.h:359
BALL::operator<<
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
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::isNotZero
bool isNotZero(const T &t)
Definition MATHS/common.h:200
BALL::Maths::isEqual
bool isEqual(const T1 &a, const T2 &b)
Definition MATHS/common.h:212
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