line.C
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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "line.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 
37 template<>
39 (
41  point2D& thisPt,
42  point2D& edgePt
43 ) const
44 {
45  vector2D u = end()-start();
46  vector2D v = e.end()-e.start();
47  vector2D w = start()-e.start();
48 
49  scalar d = u.perp(v);
50 
51  if (Foam::mag(d) > VSMALL)
52  {
53  scalar s = v.perp(w) / d;
54 
55  if (s <= SMALL)
56  {
57  thisPt = start();
58  }
59  else if (s >= (1-SMALL))
60  {
61  thisPt = end();
62  }
63  else
64  {
65  thisPt = start()+s*u;
66  }
67 
68 
69  scalar t = u.perp(w) / d;
70 
71  if (t <= SMALL)
72  {
73  edgePt = e.start();
74  }
75  else if (t >= (1-SMALL))
76  {
77  edgePt = e.end();
78  }
79  else
80  {
81  edgePt = e.start()+t*v;
82  }
83  }
84  else
85  {
86  // Parallel lines. Find overlap of both lines by projecting onto
87  // direction vector (now equal for both lines).
88 
89  scalar edge0 = e.start() & u;
90  scalar edge1 = e.end() & u;
91  bool edgeOrder = edge0 < edge1;
92 
93  scalar minEdge = (edgeOrder ? edge0 : edge1);
94  scalar maxEdge = (edgeOrder ? edge1 : edge0);
95  const point2D& minEdgePt = (edgeOrder ? e.start() : e.end());
96  const point2D& maxEdgePt = (edgeOrder ? e.end() : e.start());
97 
98  scalar this0 = start() & u;
99  scalar this1 = end() & u;
100  bool thisOrder = this0 < this1;
101 
102  scalar minThis = min(this0, this1);
103  scalar maxThis = max(this1, this0);
104  const point2D& minThisPt = (thisOrder ? start() : end());
105  const point2D& maxThisPt = (thisOrder ? end() : start());
106 
107  if (maxEdge < minThis)
108  {
109  // edge completely below *this
110  edgePt = maxEdgePt;
111  thisPt = minThisPt;
112  }
113  else if (maxEdge < maxThis)
114  {
115  // maxEdge inside interval of *this
116  edgePt = maxEdgePt;
117  thisPt = nearestDist(edgePt).rawPoint();
118  }
119  else
120  {
121  // maxEdge outside. Check if minEdge inside.
122  if (minEdge < minThis)
123  {
124  // Edge completely envelops this. Take any this point and
125  // determine nearest on edge.
126  thisPt = minThisPt;
127  edgePt = e.nearestDist(thisPt).rawPoint();
128  }
129  else if (minEdge < maxThis)
130  {
131  // minEdge inside this interval.
132  edgePt = minEdgePt;
133  thisPt = nearestDist(edgePt).rawPoint();
134  }
135  else
136  {
137  // minEdge outside this interval
138  edgePt = minEdgePt;
139  thisPt = maxThisPt;
140  }
141  }
142  }
143 
144  return Foam::mag(thisPt - edgePt);
145 }
146 
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 } // End namespace Foam
151 
152 // ************************************************************************* //
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
line.H
Foam::Vector2D< scalar >
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::line
A line primitive.
Definition: line.H:53
Foam::line::nearestDist
PointHit< Point > nearestDist(const Point &p) const
Return nearest distance to line from a given point.
Definition: lineI.H:130
Foam::Vector2D::perp
scalar perp(const Vector2D< Cmpt > &b) const
Perp dot product (dot product with perpendicular vector)
Definition: Vector2DI.H:127