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

line.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::line
00027 
00028 Description
00029     A line primitive.
00030 
00031 SourceFiles
00032     lineI.H
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef line_H
00037 #define line_H
00038 
00039 #include "vector.H"
00040 #include "PointHit.H"
00041 #include "point2D.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 // Forward declaration of classes
00049 
00050 class Istream;
00051 class Ostream;
00052 
00053 
00054 // Forward declaration of friend functions and operators
00055 
00056 template<class Point, class PointRef> class line;
00057 
00058 template<class Point, class PointRef>
00059 inline Istream& operator>>(Istream&, line<Point, PointRef>&);
00060 
00061 template<class Point, class PointRef>
00062 inline Ostream& operator<<(Ostream&, const line<Point, PointRef>&);
00063 
00064 
00065 /*---------------------------------------------------------------------------*\
00066                            Class line Declaration
00067 \*---------------------------------------------------------------------------*/
00068 
00069 template<class Point, class PointRef>
00070 class line
00071 {
00072     // Private data
00073 
00074         PointRef a_, b_;
00075 
00076 
00077 public:
00078 
00079     // Constructors
00080 
00081         //- Construct from two points
00082         inline line(const Point& start, const Point& end);
00083 
00084         //- Construct from Istream
00085         inline line(Istream&);
00086 
00087 
00088     // Member functions
00089 
00090         // Access
00091 
00092             //- Return first vertex
00093             inline PointRef start() const;
00094 
00095             //- Return second vertex
00096             inline PointRef end() const;
00097 
00098 
00099         // Properties
00100 
00101             //- Return centre (centroid)
00102             inline Point centre() const;
00103 
00104             //- Return scalar magnitude
00105             inline scalar mag() const;
00106 
00107             //- Return start-end vector
00108             inline Point vec() const;
00109 
00110             //- Return nearest distance to line from a given point
00111             //  If the nearest point is on the line, return a hit
00112             PointHit<Point> nearestDist(const Point& p) const;
00113 
00114             //- Return nearest distance from line to line. Returns distance
00115             //  and sets both points (one on *this, one on the provided
00116             //  linePointRef.
00117             scalar nearestDist
00118             (
00119                 const line<Point, const Point&>& edge,
00120                 Point& thisPoint,
00121                 Point& edgePoint
00122             ) const;
00123 
00124 
00125     // Ostream operator
00126 
00127         friend Istream& operator>> <Point, PointRef>
00128         (
00129             Istream&,
00130             line&
00131         );
00132 
00133         friend Ostream& operator<< <Point, PointRef>
00134         (
00135             Ostream&,
00136             const line&
00137         );
00138 };
00139 
00140 
00141 //- 2D specialisation
00142 template<>
00143 scalar line<point2D, const point2D&>::nearestDist
00144 (
00145     const line<point2D, const point2D&>& edge,
00146     point2D& thisPoint,
00147     point2D& edgePoint
00148 ) const;
00149 
00150 
00151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00152 
00153 } // End namespace Foam
00154 
00155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00156 
00157 #include "lineI.H"
00158 
00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00160 
00161 #endif
00162 
00163 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd