Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::line
29
30Description
31 A line primitive.
32
33SourceFiles
34 lineI.H
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_line_H
39#define Foam_line_H
40
41#include "point.H"
42#include "point2D.H"
43#include "vector.H"
44#include "pointHit.H"
45#include "FixedList.H"
46#include "UList.H"
47#include "Pair.H"
48#include "Tuple2.H"
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52namespace Foam
53{
54
55// Forward Declarations
56
57template<class Point, class PointRef> class line;
59template<class Point, class PointRef>
61
62template<class Point, class PointRef>
64
65
66// Common Typedefs
67
68//- A line using referred points
70
71
72/*---------------------------------------------------------------------------*\
73 Class linePoints Declaration
74\*---------------------------------------------------------------------------*/
75
76//- Line point storage. Default constructable (line is not)
77class linePoints
78:
79 public Pair<point>
80{
81public:
82
83 // Generated Methods
84
85 //- Default construct
86 linePoints() = default;
88 //- Inherit constructors
89 using Pair<point>::Pair;
90
91
92 // Constructors
93
94 //- Construct from point references
95 inline explicit linePoints(const linePointRef& pts);
96
97 //- Copy construct from subset of points
98 inline linePoints
99 (
100 const UList<point>& points,
101 const FixedList<label, 2>& indices
102 );
103
104
105 // Member Functions
106
107 //- The first vertex
108 const point& a() const noexcept { return Pair<point>::first(); }
109
110 //- The second vertex
111 const point& b() const noexcept { return Pair<point>::second(); }
112
113 //- The first vertex
114 point& a() noexcept { return Pair<point>::first(); }
115
116 //- The second vertex
118
119 //- Return as line reference
120 inline linePointRef ln() const;
121
123 // Properties
124
125 //- Return centre (centroid)
126 inline point centre() const;
128 //- The magnitude (length) of the line
129 inline scalar mag() const;
130
131 //- The magnitude squared (length squared) of the line
132 inline scalar magSqr() const;
133
134 //- Return start-to-end vector
135 inline vector vec() const;
136
137 //- Return the unit vector (start-to-end)
138 inline vector unitVec() const;
139
140 //- The enclosing (bounding) box for the line
141 inline Pair<point> box() const;
142};
143
144
145/*---------------------------------------------------------------------------*\
146 Class line Declaration
147\*---------------------------------------------------------------------------*/
148
149template<class Point, class PointRef>
150class line
151{
152 // Private Data
153
154 //- Reference to the first line point
155 PointRef a_;
156
157 //- Reference to the second line point
158 PointRef b_;
159
160
161public:
162
163 // Constructors
164
165 //- Construct from two points
166 inline line(const Point& from, const Point& to);
167
168 //- Construct from two points in the list of points
169 // The indices could be from edge etc.
170 inline line
171 (
172 const UList<Point>& points,
173 const FixedList<label, 2>& indices
174 );
175
176 //- Construct from Istream
177 inline explicit line(Istream& is);
178
180 // Member Functions
181
182 // Access
183
184 //- The first point
185 PointRef a() const noexcept { return a_; }
186
187 //- The second point
188 PointRef b() const noexcept { return b_; }
189
190 //- The first point
191 PointRef first() const noexcept { return a_; }
192
193 //- The second (last) point
194 PointRef second() const noexcept { return b_; }
195
196 //- The start (first) point
197 PointRef start() const noexcept { return a_; }
198
199 //- The end (second) point
200 PointRef end() const noexcept { return b_; }
202 //- The last (second) point
203 PointRef last() const noexcept { return b_; }
204
205
206 // Line properties (static calculations)
207
208 //- The enclosing (bounding) box for two points
209 inline static Pair<Point> box(const Point& p0, const Point& p1);
210
211
212 // Properties
213
214 //- Return centre (centroid)
215 inline Point centre() const;
216
217 //- The magnitude (length) of the line
218 inline scalar mag() const;
219
220 //- The magnitude squared (length squared) of the line
221 inline scalar magSqr() const;
222
223 //- Return start-to-end vector
224 inline Point vec() const;
225
226 //- Return the unit vector (start-to-end)
227 inline Point unitVec() const;
228
229 //- The enclosing (bounding) box for the line
230 inline Pair<Point> box() const;
231
232 //- Return nearest distance to line from a given point
233 // If the nearest point is on the line, return a hit
234 PointHit<Point> nearestDist(const Point& p) const;
235
236 //- Return nearest distance from line to line.
237 //- Returns distance and sets both points
238 //- (one on *this, one on the provided linePointRef.
239 scalar nearestDist
240 (
242 Point& thisPoint,
243 Point& edgePoint
244 ) const;
245
246
247 // IOstream Operators
248
249 friend Istream& operator>> <Point, PointRef>(Istream&, line&);
251};
253
254//- 2D specialisation
255template<>
259 point2D& thisPoint,
260 point2D& edgePoint
261) const;
262
263
264// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266} // End namespace Foam
267
268// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269
270#include "lineI.H"
271
272// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274#endif
275
276// ************************************************************************* //
CGAL::Point_3< K > Point
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
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:59
An ordered pair of two objects of type <T> with first() and second() elements.
Definition Pair.H:66
const T & first() const noexcept
Access the first element.
Definition Pair.H:137
const T & second() const noexcept
Access the second element.
Definition Pair.H:147
Describes the interaction of a object and a (templated) point. It carries the info of a successful hi...
Definition pointHit.H:60
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:89
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition edge.H:62
vector vec() const
Return start-to-end vector.
Definition lineI.H:128
point & b() noexcept
The second vertex.
Definition line.H:132
linePointRef ln() const
Return as line reference.
Definition lineI.H:76
point & a() noexcept
The first vertex.
Definition line.H:127
const point & b() const noexcept
The second vertex.
Definition line.H:122
Pair< point > box() const
The enclosing (bounding) box for the line.
Definition lineI.H:172
scalar mag() const
The magnitude (length) of the line.
Definition lineI.H:102
const point & a() const noexcept
The first vertex.
Definition line.H:117
scalar magSqr() const
The magnitude squared (length squared) of the line.
Definition lineI.H:115
vector unitVec() const
Return the unit vector (start-to-end).
Definition lineI.H:148
linePoints()=default
Default construct.
point centre() const
Return centre (centroid).
Definition lineI.H:89
A line primitive.
Definition line.H:180
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.
Definition lineI.H:180
PointRef end() const noexcept
The end (second) point.
Definition line.H:252
line(const Point &from, const Point &to)
Construct from two points.
Definition lineI.H:45
PointRef a() const noexcept
The first point.
Definition line.H:227
PointRef first() const noexcept
The first point.
Definition line.H:237
scalar nearestDist(const line< Point, const Point & > &edge, Point &thisPoint, Point &edgePoint) const
Return nearest distance from line to line. Returns distance and sets both points (one on *this,...
Definition lineI.H:212
PointRef second() const noexcept
The second (last) point.
Definition line.H:242
line(const UList< Point > &points, const FixedList< label, 2 > &indices)
Construct from two points in the list of points.
Definition lineI.H:57
Point centre() const
Return centre (centroid).
Definition lineI.H:83
friend Ostream & operator(Ostream &, const line &)
line(Istream &is)
Construct from Istream.
Definition lineI.H:68
PointRef last() const noexcept
The last (second) point.
Definition line.H:257
scalar mag() const
The magnitude (length) of the line.
Definition lineI.H:96
static Pair< Point > box(const Point &p0, const Point &p1)
The enclosing (bounding) box for two points.
Definition lineI.H:156
Point unitVec() const
Return the unit vector (start-to-end).
Definition lineI.H:135
Pair< Point > box() const
The enclosing (bounding) box for the line.
Definition lineI.H:166
scalar magSqr() const
The magnitude squared (length squared) of the line.
Definition lineI.H:109
PointRef b() const noexcept
The second point.
Definition line.H:232
PointRef start() const noexcept
The start (first) point.
Definition line.H:247
Point vec() const
Return start-to-end vector.
Definition lineI.H:122
volScalarField & p
const volScalarField & p0
Definition EEqn.H:36
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
Namespace for OpenFOAM.
vector2D point2D
Point2D is a vector.
Definition point2D.H:37
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
line< point, const point & > linePointRef
A line using referred points.
Definition line.H:66
vector point
Point is a vector.
Definition point.H:37
const direction noexcept
Definition scalarImpl.H:265
Vector< scalar > vector
Definition vector.H:57
const pointField & pts