OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

plane.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::plane
00027 
00028 Description
00029     Geometric class that creates a 2D plane and can return the intersection
00030      point between a line and the plane.
00031 
00032 SourceFiles
00033     plane.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef plane_H
00038 #define plane_H
00039 
00040 #include "point.H"
00041 #include "scalarList.H"
00042 #include "dictionary.H"
00043 #include "line.H"
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 namespace Foam
00048 {
00049 
00050 // Forward declaration of friend functions and operators
00051 
00052 class plane;
00053 bool operator==(const plane&, const plane&);
00054 bool operator!=(const plane&, const plane&);
00055 Ostream& operator<<(Ostream&, const plane&);
00056 
00057 
00058 /*---------------------------------------------------------------------------*\
00059                            Class plane Declaration
00060 \*---------------------------------------------------------------------------*/
00061 
00062 class plane
00063 {
00064 public:
00065 
00066         //- A direction and a reference point
00067         class ray
00068         {
00069             point refPoint_;
00070 
00071             vector dir_;
00072 
00073         public:
00074 
00075             ray(const point& refPoint, const vector& dir)
00076             :
00077                 refPoint_(refPoint),
00078                 dir_(dir)
00079             {}
00080 
00081             const point& refPoint() const
00082             {
00083                 return refPoint_;
00084             }
00085 
00086             const vector& dir() const
00087             {
00088                 return dir_;
00089             }
00090         };
00091 
00092 
00093 private:
00094 
00095     // Private data
00096 
00097         //- Plane normal
00098         vector unitVector_;
00099 
00100         //- Base point
00101         point basePoint_;
00102 
00103 
00104     // Private Member Functions
00105 
00106         //- Calculates basePoint and normal vector given plane coefficients
00107         void calcPntAndVec(const scalarList& C);
00108 
00109         //- Calculates basePoint and normal vector given three points
00110         //- Normal vector determined using right hand rule
00111         void calcPntAndVec
00112         (
00113             const point& point1,
00114             const point& point2,
00115             const point& point3
00116         );
00117 
00118 
00119 public:
00120 
00121     // Constructors
00122 
00123         //- Construct from normal vector through the origin
00124         plane(const vector& normalVector);
00125 
00126         //- Construct from normal vector and point in plane
00127         plane(const point& basePoint, const vector& normalVector);
00128 
00129         //- Construct from three points in plane
00130         plane(const point& point1, const point& point2, const point& point3);
00131 
00132         //- Construct from coefficients for the
00133         //  plane equation: ax + by + cz + d = 0
00134         plane(const scalarList& C);
00135 
00136         //- Construct from dictionary
00137         plane(const dictionary& planeDict);
00138 
00139         //- Construct from Istream. Assumes the base + normal notation.
00140         plane(Istream& is);
00141 
00142 
00143     // Member Functions
00144 
00145         //- Return plane normal
00146         const vector& normal() const;
00147 
00148         //- Return or return plane base point
00149         const point& refPoint() const;
00150 
00151         //- Return coefficients for the
00152         //  plane equation: ax + by + cz + d = 0
00153         scalarList planeCoeffs() const;
00154 
00155         //- Return nearest point in the plane for the given point
00156         point nearestPoint(const point& p) const;
00157 
00158         //- Return distance from the given point to the plane
00159         scalar distance(const point& p) const;
00160 
00161         //- Return cut coefficient for plane and line defined by
00162         //  origin and direction
00163         scalar normalIntersect(const point& pnt0, const vector& dir) const;
00164 
00165         //- Return cut coefficient for plane and ray
00166         scalar normalIntersect(const ray& r) const
00167         {
00168             return normalIntersect(r.refPoint(), r.dir());
00169         }
00170 
00171         //- Return the cutting point between the plane and
00172         // a line passing through the supplied points
00173         template<class Point, class PointRef>
00174         scalar lineIntersect(const line<Point, PointRef>& l) const
00175         {
00176             return normalIntersect(l.start(), l.vec());
00177         }
00178 
00179         //- Return the cutting line between this plane and another.
00180         //  Returned as direction vector and point line goes through.
00181         ray planeIntersect(const plane&) const;
00182 
00183         //- Return the cutting point between this plane and two other planes
00184         point planePlaneIntersect(const plane&, const plane&) const;
00185 
00186 
00187     // friend Operators
00188 
00189         friend bool operator==(const plane&, const plane&);
00190         friend bool operator!=(const plane&, const plane&);
00191 
00192 
00193     // IOstream Operators
00194 
00195         //- Write plane properties
00196         friend Ostream& operator<<(Ostream&, const plane&);
00197 };
00198 
00199 
00200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00201 
00202 } // End namespace Foam
00203 
00204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00205 
00206 #endif
00207 
00208 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd