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-2021 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 Declarations
53 
54 template<class Point, class PointRef> class line;
55 
56 template<class Point, class PointRef>
58 
59 template<class Point, class PointRef>
61 
62 
63 /*---------------------------------------------------------------------------*\
64  Class line Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 template<class Point, class PointRef>
68 class line
69 {
70  // Private Data
71 
72  //- First point
73  PointRef a_;
74 
75  //- Second point
76  PointRef b_;
77 
78 
79 public:
80 
81  // Constructors
82 
83  //- Construct from two points
84  inline line(const Point& from, const Point& to);
85 
86  //- Construct from two points in the list of points
87  // The indices could be from edge etc.
88  inline line
89  (
90  const UList<Point>& points,
91  const FixedList<label, 2>& indices
92  );
93 
94  //- Construct from Istream
95  inline explicit line(Istream& is);
96 
97 
98  // Member Functions
99 
100  // Access
101 
102  //- Return first point
103  inline PointRef first() const noexcept;
104 
105  //- Return second (last) point
106  inline PointRef second() const noexcept;
107 
108  //- Return last (second) point
109  inline PointRef last() const noexcept;
110 
111  //- Return first point
112  inline PointRef start() const noexcept;
113 
114  //- Return second (last) point
115  inline PointRef end() const noexcept;
116 
117 
118  // Properties
119 
120  //- Return centre (centroid)
121  inline Point centre() const;
122 
123  //- Return scalar magnitude
124  inline scalar mag() const;
125 
126  //- Return start-to-end vector
127  inline Point vec() const;
128 
129  //- Return the unit vector (start-to-end)
130  inline Point unitVec() const;
131 
132  //- Return nearest distance to line from a given point
133  // If the nearest point is on the line, return a hit
134  PointHit<Point> nearestDist(const Point& p) const;
135 
136  //- Return nearest distance from line to line. Returns distance
137  // and sets both points (one on *this, one on the provided
138  // linePointRef.
139  scalar nearestDist
140  (
141  const line<Point, const Point&>& edge,
142  Point& thisPoint,
143  Point& edgePoint
144  ) const;
145 
146 
147  // IOstream operators
148 
149  friend Istream& operator>> <Point, PointRef>
150  (
151  Istream& is,
152  line& l
153  );
154 
155  friend Ostream& operator<< <Point, PointRef>
156  (
157  Ostream& os,
158  const line& l
159  );
160 };
161 
162 
163 //- 2D specialisation
164 template<>
165 scalar line<point2D, const point2D&>::nearestDist
166 (
167  const line<point2D, const point2D&>& edge,
168  point2D& thisPoint,
169  point2D& edgePoint
170 ) const;
171 
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 } // End namespace Foam
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 #include "lineI.H"
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************************************************************* //
Foam::line::line
line(const Point &from, const Point &to)
Construct from two points.
Definition: lineI.H:35
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::start
PointRef start() const noexcept
Return first point.
Definition: lineI.H:85
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::Vector2D< scalar >
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
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::end
PointRef end() const noexcept
Return second (last) point.
Definition: lineI.H:91
Foam::line::second
PointRef second() const noexcept
Return second (last) point.
Definition: lineI.H:71
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::line::last
PointRef last() const noexcept
Return last (second) point.
Definition: lineI.H:78
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
UList.H
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:53
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::operator
friend Ostream & operator(Ostream &os, const line &l)
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
Foam::line::first
PointRef first() const noexcept
Return first point.
Definition: lineI.H:64