OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     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 /*---------------------------------------------------------------------------*\
00051                            Class plane Declaration
00052 \*---------------------------------------------------------------------------*/
00053 
00054 class plane
00055 {
00056 public:
00057 
00058         class ray
00059         {
00060             point refPoint_;
00061 
00062             vector dir_;
00063 
00064         public:
00065 
00066             ray(const point& refPoint, const vector& dir)
00067             :
00068                 refPoint_(refPoint),
00069                 dir_(dir)
00070             {}
00071 
00072             const point& refPoint() const
00073             {
00074                 return refPoint_;
00075             }
00076 
00077             const vector& dir() const
00078             {
00079                 return dir_;
00080             }
00081         };
00082 
00083 private:
00084     // Private data
00085 
00086         //- Plane normal
00087         vector unitVector_;
00088 
00089         //- Base point
00090         point basePoint_;
00091 
00092 
00093     // Private Member Functions
00094 
00095         //- Calculates basePoint and normal vector given plane coefficients
00096         void calcPntAndVec(const scalarList& C);
00097 
00098         //- Calculates basePoint and normal vector given three points
00099         //- Normal vector determined using right hand rule
00100         void calcPntAndVec
00101         (
00102             const point& point1,
00103             const point& point2,
00104             const point& point3
00105         );
00106 
00107 public:
00108 
00109     // Constructors
00110 
00111         //- Construct null
00112         plane();
00113  
00114         //- Construct from normal vector and point in plane
00115         plane(const point& basePoint, const vector& normalVector);
00116  
00117         //- Construct from three points in plane
00118         plane(const point& point1, const point& point2, const point& point3);
00119 
00120         //- Construct from coefficients for the
00121         //  plane equation: ax + by + cz + d = 0
00122         plane(const scalarList& C);
00123 
00124         //- Construct from dictionary
00125         plane(const dictionary& planeDict);
00126 
00127         //- Construct from Istream. Assumes the base + normal notation.
00128         plane(Istream& is);
00129 
00130 
00131     // Member Functions
00132 
00133         //- Return plane normal
00134         const vector& normal() const;
00135 
00136         //- Return or return plane base point
00137         const point& refPoint() const;
00138 
00139         //- Return coefficients for the
00140         //  plane equation: ax + by + cz + d = 0
00141         scalarList planeCoeffs() const;
00142 
00143         //- Return nearest point in the plane for the given point
00144         point nearestPoint(const point& p) const;
00145 
00146         //- Return distance from the given point to the plane
00147         scalar distance(const point& p) const;
00148 
00149         //- Return cut coefficient for plane and line defined by
00150         //  origin and direction
00151         scalar normalIntersect(const point& pnt0, const vector& dir) const;
00152 
00153         //- Return cut coefficient for plane and ray
00154         scalar normalIntersect(const ray& r) const
00155         {
00156             return normalIntersect(r.refPoint(), r.dir());
00157         }
00158 
00159         //- Return the cutting point between the plane and
00160         // a line passing through the supplied points
00161         template<class Point, class PointRef>
00162         scalar lineIntersect(const line<Point, PointRef>& l) const
00163         {
00164             return normalIntersect(l.start(), l.vec());
00165         }
00166 
00167         //- Return the cutting line between this plane and another.
00168         //  Returned as direction vector and point line goes through.
00169         ray planeIntersect(const plane&) const;
00170 
00171         //- Return the cutting point between this plane and two other planes
00172         point planePlaneIntersect(const plane&, const plane&) const;
00173 
00174     // IOstream Operators
00175 
00176         //- Write plane properties
00177         friend Ostream& operator<<(Ostream&, const plane&);
00178 
00179 };
00180 
00181 
00182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00183 
00184 } // End namespace Foam
00185 
00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00187 
00188 #endif
00189 
00190 // ************************************************************************* //
For further information go to www.openfoam.org