Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Saf/Math/Algebra/Hyperplane.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Simple Application Framework (Saf) library.
00003     Copyright (C) 2010 - 2012 Ondrej Danek <ondrej.danek@gmail.com>
00004 
00005     This library is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published 
00007     by the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     Saf is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Simple Application Framework library. If not, 
00017     see <http://www.gnu.org/licenses/>.
00018 */
00019 
00028 #ifndef SAF_MATH_ALGEBRA_HYPERPLANE_H
00029 #define SAF_MATH_ALGEBRA_HYPERPLANE_H
00030 
00031 #include "Vector.h"
00032 
00033 namespace Saf
00034 {
00035     namespace Math
00036     {
00037         namespace Algebra
00038         {
00046             template <Size N, class T>
00047             class Hyperplane
00048             {
00049             private:
00051                 Vector<N,T> m_normal;
00053                 T m_d;
00054 
00055             public:
00057                 Hyperplane()                        
00058                 {}
00059 
00061                 Hyperplane(const Vector<N,T> &normal, const Vector<N,T> &point)
00062                 {
00063                     Set(normal, point);
00064                 }
00065 
00067                 Hyperplane(const Hyperplane<N,T> &p)
00068                 {
00069                     *this = p;
00070                 }
00071 
00073                 void Set(const Vector<N,T> &normal, const Vector<N,T> &point)
00074                 {
00075                     m_normal = normal.Normalized();
00076                     m_d = m_normal.DotProduct(point);
00077                 }
00078 
00080                 const Vector<N,T> &Normal() const
00081                 {
00082                     return m_normal;
00083                 }
00084 
00086                 T Distance() const
00087                 {
00088                     return m_d;
00089                 }
00090 
00092                 bool IsAbove (const Vector<N,T> &point) const
00093                 {
00094                     return m_normal.DotProduct(point) > m_d;
00095                 }
00096 
00098                 Hyperplane<N,T>& operator= (const Hyperplane<N,T> &p)
00099                 {
00100                     m_normal = p.m_normal;
00101                     m_d = p.m_d;
00102                     return *this;
00103                 }
00104             };
00105         }
00106     }
00107 }
00108 
00109 #endif