line.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::line
29 
30 Description
31  A line primitive.
32 
33 SourceFiles
34  lineI.H
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef line_H
39 #define line_H
40 
41 #include "vector.H"
42 #include "PointHit.H"
43 #include "point2D.H"
44 #include "FixedList.H"
45 #include "UList.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of classes
53 
54 class Istream;
55 class Ostream;
56 
57 
58 // Forward declaration of friend functions and operators
59 
60 template<class Point, class PointRef> class line;
61 
62 template<class Point, class PointRef>
64 
65 template<class Point, class PointRef>
66 inline Ostream& operator<<(Ostream& os, const line<Point, PointRef>& l);
67 
68 
69 /*---------------------------------------------------------------------------*\
70  Class line Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 template<class Point, class PointRef>
74 class line
75 {
76  // Private data
77 
78  //- First point
79  PointRef a_;
80 
81  //- Second point
82  PointRef b_;
83 
84 
85 public:
86 
87  // Constructors
88 
89  //- Construct from two points
90  inline line(const Point& start, const Point& end);
91 
92  //- Construct from two points in the list of points
93  // The indices could be from edge etc.
94  inline line
95  (
96  const UList<Point>& points,
97  const FixedList<label, 2>& indices
98  );
99 
100  //- Construct from Istream
101  inline explicit line(Istream& is);
102 
103 
104  // Member Functions
105 
106  // Access
107 
108  //- Return first point
109  inline PointRef first() const;
110 
111  //- Return second (last) point
112  inline PointRef second() const;
113 
114  //- Return last (second) point
115  inline PointRef last() const;
116 
117  //- Return first point
118  inline PointRef start() const;
119 
120  //- Return second (last) point
121  inline PointRef end() const;
122 
123 
124  // Properties
125 
126  //- Return centre (centroid)
127  inline Point centre() const;
128 
129  //- Return scalar magnitude
130  inline scalar mag() const;
131 
132  //- Return start-to-end vector
133  inline Point vec() const;
134 
135  //- Return the unit vector (start-to-end)
136  inline Point unitVec() const;
137 
138  //- Return nearest distance to line from a given point
139  // If the nearest point is on the line, return a hit
140  PointHit<Point> nearestDist(const Point& p) const;
141 
142  //- Return nearest distance from line to line. Returns distance
143  // and sets both points (one on *this, one on the provided
144  // linePointRef.
145  scalar nearestDist
146  (
148  Point& thisPoint,
149  Point& edgePoint
150  ) const;
151 
152 
153  // IOstream operators
154 
155  friend Istream& operator>> <Point, PointRef>
156  (
157  Istream& is,
158  line& l
159  );
160 
161  friend Ostream& operator<< <Point, PointRef>
162  (
163  Ostream& os,
164  const line& l
165  );
166 };
167 
168 
169 //- 2D specialisation
170 template<>
172 (
174  point2D& thisPoint,
175  point2D& edgePoint
176 ) const;
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #include "lineI.H"
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
Foam::line::centre
Point centre() const
Return centre (centroid)
Definition: lineI.H:98
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::PointHit
Describes the interaction of a face and a point. It carries the info of a successful hit and (if succ...
Definition: PointHit.H:53
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::line::last
PointRef last() const
Return last (second) point.
Definition: lineI.H:78
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::line::start
PointRef start() const
Return first point.
Definition: lineI.H:85
Foam::line::end
PointRef end() const
Return second (last) point.
Definition: lineI.H:91
Foam::Vector2D< scalar >
lineI.H
Foam::line::second
PointRef second() const
Return second (last) point.
Definition: lineI.H:71
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::line::line
line(const Point &start, const Point &end)
Construct from two points.
Definition: lineI.H:35
point2D.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::line::mag
scalar mag() const
Return scalar magnitude.
Definition: lineI.H:105
Foam::line::unitVec
Point unitVec() const
Return the unit vector (start-to-end)
Definition: lineI.H:119
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
UList.H
Foam::line::first
PointRef first() const
Return first point.
Definition: lineI.H:64
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
PointHit.H
Foam::line
A line primitive.
Definition: line.H:59
vector.H
Point
CGAL::Point_3< K > Point
Definition: CGALIndexedPolyhedron.H:53
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
FixedList.H
Foam::line::nearestDist
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.
Definition: lineI.H:130
Foam::line::vec
Point vec() const
Return start-to-end vector.
Definition: lineI.H:112