00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::plane 00026 00027 Description 00028 Geometric class that creates a 2D plane and can return the intersection 00029 point between a line and the plane. 00030 00031 SourceFiles 00032 plane.C 00033 00034 \*---------------------------------------------------------------------------*/ 00035 00036 #ifndef plane_H 00037 #define plane_H 00038 00039 #include <OpenFOAM/point.H> 00040 #include <OpenFOAM/scalarList.H> 00041 #include <OpenFOAM/dictionary.H> 00042 #include <OpenFOAM/line.H> 00043 00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00045 00046 namespace Foam 00047 { 00048 00049 // Forward declaration of friend functions and operators 00050 00051 class plane; 00052 bool operator==(const plane&, const plane&); 00053 bool operator!=(const plane&, const plane&); 00054 Ostream& operator<<(Ostream&, const plane&); 00055 00056 00057 /*---------------------------------------------------------------------------*\ 00058 Class plane Declaration 00059 \*---------------------------------------------------------------------------*/ 00060 00061 class plane 00062 { 00063 public: 00064 00065 //- A direction and a reference point 00066 class ray 00067 { 00068 point refPoint_; 00069 00070 vector dir_; 00071 00072 public: 00073 00074 ray(const point& refPoint, const vector& dir) 00075 : 00076 refPoint_(refPoint), 00077 dir_(dir) 00078 {} 00079 00080 const point& refPoint() const 00081 { 00082 return refPoint_; 00083 } 00084 00085 const vector& dir() const 00086 { 00087 return dir_; 00088 } 00089 }; 00090 00091 00092 private: 00093 00094 // Private data 00095 00096 //- Plane normal 00097 vector unitVector_; 00098 00099 //- Base point 00100 point basePoint_; 00101 00102 00103 // Private Member Functions 00104 00105 //- Calculates basePoint and normal vector given plane coefficients 00106 void calcPntAndVec(const scalarList& C); 00107 00108 //- Calculates basePoint and normal vector given three points 00109 //- Normal vector determined using right hand rule 00110 void calcPntAndVec 00111 ( 00112 const point& point1, 00113 const point& point2, 00114 const point& point3 00115 ); 00116 00117 00118 public: 00119 00120 // Constructors 00121 00122 //- Construct from normal vector through the origin 00123 plane(const vector& normalVector); 00124 00125 //- Construct from normal vector and point in plane 00126 plane(const point& basePoint, const vector& normalVector); 00127 00128 //- Construct from three points in plane 00129 plane(const point& point1, const point& point2, const point& point3); 00130 00131 //- Construct from coefficients for the 00132 // plane equation: ax + by + cz + d = 0 00133 plane(const scalarList& C); 00134 00135 //- Construct from dictionary 00136 plane(const dictionary& planeDict); 00137 00138 //- Construct from Istream. Assumes the base + normal notation. 00139 plane(Istream& is); 00140 00141 00142 // Member Functions 00143 00144 //- Return plane normal 00145 const vector& normal() const; 00146 00147 //- Return or return plane base point 00148 const point& refPoint() const; 00149 00150 //- Return coefficients for the 00151 // plane equation: ax + by + cz + d = 0 00152 FixedList<scalar, 4> planeCoeffs() const; 00153 00154 //- Return nearest point in the plane for the given point 00155 point nearestPoint(const point& p) const; 00156 00157 //- Return distance from the given point to the plane 00158 scalar distance(const point& p) const; 00159 00160 //- Return cut coefficient for plane and line defined by 00161 // origin and direction 00162 scalar normalIntersect(const point& pnt0, const vector& dir) const; 00163 00164 //- Return cut coefficient for plane and ray 00165 scalar normalIntersect(const ray& r) const 00166 { 00167 return normalIntersect(r.refPoint(), r.dir()); 00168 } 00169 00170 //- Return the cutting point between the plane and 00171 // a line passing through the supplied points 00172 template<class Point, class PointRef> 00173 scalar lineIntersect(const line<Point, PointRef>& l) const 00174 { 00175 return normalIntersect(l.start(), l.vec()); 00176 } 00177 00178 //- Return the cutting line between this plane and another. 00179 // Returned as direction vector and point line goes through. 00180 ray planeIntersect(const plane&) const; 00181 00182 //- Return the cutting point between this plane and two other planes 00183 point planePlaneIntersect(const plane&, const plane&) const; 00184 00185 //- Write to dictionary 00186 void writeDict(Ostream&) const; 00187 00188 00189 // friend Operators 00190 00191 friend bool operator==(const plane&, const plane&); 00192 friend bool operator!=(const plane&, const plane&); 00193 00194 00195 // IOstream Operators 00196 00197 //- Write plane properties 00198 friend Ostream& operator<<(Ostream&, const plane&); 00199 }; 00200 00201 00202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00203 00204 } // End namespace Foam 00205 00206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00207 00208 #endif 00209 00210 // ************************ vim: set sw=4 sts=4 et: ************************ //