plane.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-2026 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::plane
26 
27 Description
28  Geometric class that creates a 2D plane and can return the intersection
29  point between a line and the plane.
30 
31 SourceFiles
32  plane.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef plane_H
37 #define plane_H
38 
39 #include "point.H"
40 #include "scalarList.H"
41 #include "dictionary.H"
42 #include "NamedEnum.H"
43 #include "line.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declaration of friend functions and operators
51 
52 class plane;
53 bool operator==(const plane&, const plane&);
54 bool operator!=(const plane&, const plane&);
55 Ostream& operator<<(Ostream&, const plane&);
56 
57 
58 /*---------------------------------------------------------------------------*\
59  Class plane Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class plane
63 {
64  // Private Types
65 
66  //- Ways in which the plane can be specified
67  enum class specification
68  {
69  planeEquation,
70  embeddedPoints,
71  pointAndNormal
72  };
73 
74  //- Names of the ways in which the plane can be specified
75  static const NamedEnum<specification, 3> specificationNames_;
76 
77 
78 public:
79 
80  // Public Types
81 
82  //- A direction and a reference point
83  class ray
84  {
85  point refPoint_;
86 
87  vector dir_;
88 
89  public:
90 
91  ray(const point& refPoint, const vector& dir)
92  :
93  refPoint_(refPoint),
94  dir_(dir)
95  {}
96 
97  const point& refPoint() const
98  {
99  return refPoint_;
100  }
101 
102  const vector& dir() const
103  {
104  return dir_;
105  }
106  };
107 
108 
109 private:
110 
111  // Private Data
112 
113  //- Normal
114  vector normal_;
115 
116  //- Reference point
117  point point_;
118 
119 
120  // Private Member Functions
121 
122  //- Calculates basePoint and normal vector given plane coefficients
123  void calcPntAndVec
124  (
125  const scalar C1,
126  const scalar C2,
127  const scalar C3,
128  const scalar C4
129  );
130 
131  //- Calculates basePoint and normal vector given three points
132  void calcPntAndVec
133  (
134  const point& point1,
135  const point& point2,
136  const point& point3
137  );
138 
139 
140 public:
141 
142  // Constructors
143 
144  //- Construct from normal vector through the origin
145  explicit plane(const vector& normalVector);
146 
147  //- Construct from normal vector and point in plane
148  plane(const point& basePoint, const vector& normalVector);
149 
150  //- Construct from three points in plane
151  plane
152  (
153  const point& point1,
154  const point& point2,
155  const point& point3
156  );
157 
158  //- Construct from coefficients for the plane equation,
159  // ax + by + cz + d = 0
160  explicit plane
161  (
162  const scalar a,
163  const scalar b,
164  const scalar c,
165  const scalar d
166  );
167 
168  //- Construct from dictionary
169  explicit plane(const dictionary& planeDict);
170 
171  //- Construct from Istream
172  explicit plane(Istream& is);
173 
174 
175  // Member Functions
176 
177  //- Return whether or not this plane is valid
178  inline bool valid() const
179  {
180  return normal_ != vector::zero && point_ != point::max;
181  }
182 
183  //- Return the plane normal
184  inline const vector& normal() const
185  {
186  return normal_;
187  }
188 
189  //- Return the plane base point
190  inline const point& refPoint() const
191  {
192  return point_;
193  }
194 
195  //- Return coefficients for the plane equation, ax + by + cz + d = 0
197 
198  //- Return a point on the plane
199  point aPoint() const;
200 
201  //- Return nearest point in the plane for the given point
202  point nearestPoint(const point& p) const;
203 
204  //- Return distance from the given point to the plane
205  scalar distance(const point& p) const;
206 
207  //- Return signed distance from the given point to the plane
208  scalar signedDistance(const point& p) const;
209 
210  //- Return cut coefficient for plane and line defined by
211  // origin and direction
212  scalar normalIntersect(const point& pnt0, const vector& dir) const;
213 
214  //- Return cut coefficient for plane and ray
215  inline scalar normalIntersect(const ray& r) const
216  {
217  return normalIntersect(r.refPoint(), r.dir());
218  }
219 
220  //- Return the cutting point between the plane and
221  // a line passing through the supplied points
222  template<class Point, class PointRef>
223  inline scalar lineIntersect(const line<Point, PointRef>& l) const
224  {
225  return normalIntersect(l.start(), l.vec());
226  }
227 
228  //- Return the cutting line between this plane and another.
229  // Returned as direction vector and point line goes through.
230  ray planeIntersect(const plane&) const;
231 
232  //- Return the cutting point between this plane and two other planes
233  point planePlaneIntersect(const plane&, const plane&) const;
234 
235  //- Mirror the supplied point in the plane. Return the mirrored point.
236  point mirror(const point& p) const;
237 
238  //- Write to dictionary
239  void writeDict(Ostream&) const;
240 
241 
242  // friend Operators
243 
244  friend bool operator==(const plane&, const plane&);
245  friend bool operator!=(const plane&, const plane&);
246 
247 
248  // IOstream Operators
249 
250  //- Write plane properties
251  friend Ostream& operator<<(Ostream&, const plane&);
252 };
253 
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 } // End namespace Foam
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:78
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
static const Form zero
Definition: VectorSpace.H:118
static const Form max
Definition: VectorSpace.H:120
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A line primitive.
Definition: line.H:71
PointRef start() const
Return first vertex.
Definition: lineI.H:60
Point vec() const
Return start-end vector.
Definition: lineI.H:87
A direction and a reference point.
Definition: plane.H:83
const point & refPoint() const
Definition: plane.H:96
ray(const point &refPoint, const vector &dir)
Definition: plane.H:90
const vector & dir() const
Definition: plane.H:101
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:62
const point & refPoint() const
Return the plane base point.
Definition: plane.H:189
point mirror(const point &p) const
Mirror the supplied point in the plane. Return the mirrored point.
Definition: plane.C:466
FixedList< scalar, 4 > planeCoeffs() const
Return coefficients for the plane equation, ax + by + cz + d = 0.
Definition: plane.C:231
friend bool operator!=(const plane &, const plane &)
scalar normalIntersect(const point &pnt0, const vector &dir) const
Return cut coefficient for plane and line defined by.
Definition: plane.C:364
bool valid() const
Return whether or not this plane is valid.
Definition: plane.H:177
plane(const vector &normalVector)
Construct from normal vector through the origin.
Definition: plane.C:88
friend Ostream & operator<<(Ostream &, const plane &)
Write plane properties.
scalar distance(const point &p) const
Return distance from the given point to the plane.
Definition: plane.C:351
const vector & normal() const
Return the plane normal.
Definition: plane.H:183
point aPoint() const
Return a point on the plane.
Definition: plane.C:278
void writeDict(Ostream &) const
Write to dictionary.
Definition: plane.C:481
scalar lineIntersect(const line< Point, PointRef > &l) const
Return the cutting point between the plane and.
Definition: plane.H:222
point nearestPoint(const point &p) const
Return nearest point in the plane for the given point.
Definition: plane.C:345
ray planeIntersect(const plane &) const
Return the cutting line between this plane and another.
Definition: plane.C:376
friend bool operator==(const plane &, const plane &)
point planePlaneIntersect(const plane &, const plane &) const
Return the cutting point between this plane and two other planes.
Definition: plane.C:444
scalar signedDistance(const point &p) const
Return signed distance from the given point to the plane.
Definition: plane.C:357
volScalarField & b
Definition: createFields.H:27
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
bool operator!=(const particle &, const particle &)
Definition: particle.C:445
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
volScalarField & p