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