FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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