00001
00002
00003
00004
00005 #include "geometry/Plane.h"
00006 #include <cfloat>
00007
00008
00009 Plane::Plane(const Point& o, const Vector& n)
00010 : Surface(o, n.unit())
00011 , m_d(n.magnitude())
00012 {
00013 if(m_d==0)
00014 FATAL("Plane constructor called with null unit vector");
00015
00016 }
00017 Plane::Plane(const Point& o, const Vector& n, double dist)
00018 : Surface(o, n.unit())
00019 , m_d(dist)
00020 {}
00021
00022
00023 double
00024 Plane::distance( const Point& x, const Vector& vhat, int inout)const
00025 {
00026
00027 double denom = vhat*direction();
00028 return ( denom*inout<=0 )? FLT_MAX : how_near(x)/denom;
00029 }
00030
00031 void
00032 Plane::reverse()
00033 {
00034 Surface::reverse();
00035 m_d *=-1.;
00036 }
00037
00038 Vector Plane::normal(const Point& ) const
00039 {
00040 return Surface::direction();
00041 }
00042
00043 Surface&
00044 Plane::copy()const
00045 {
00046 return *new Plane(origin(), direction(), m_d);
00047 }
00048 void
00049 Plane::printOn( std::ostream& os ) const
00050 { os << "Plane: origin= " << origin()
00051 << ",\t normal= " << direction()
00052 << ",\t distance= " << m_d
00053 << "\n";
00054 }
00055
00056
00057
00058
00059