1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 scalar line<point2D, const point2D&>::nearestDist
39 const line<point2D, const point2D&>& e,
44 vector2D u = end()-start();
45 vector2D v = e.end()-e.start();
46 vector2D w = start()-e.start();
50 if (Foam::mag(d) > VSMALL)
52 scalar s = v.perp(w) / d;
58 else if (s >= (1-SMALL))
68 scalar t = u.perp(w) / d;
74 else if (t >= (1-SMALL))
80 edgePt = e.start()+t*v;
85 // Parallel lines. Find overlap of both lines by projecting onto
86 // direction vector (now equal for both lines).
88 scalar edge0 = e.start() & u;
89 scalar edge1 = e.end() & u;
90 bool edgeOrder = edge0 < edge1;
92 scalar minEdge = (edgeOrder ? edge0 : edge1);
93 scalar maxEdge = (edgeOrder ? edge1 : edge0);
94 const point2D& minEdgePt = (edgeOrder ? e.start() : e.end());
95 const point2D& maxEdgePt = (edgeOrder ? e.end() : e.start());
97 scalar this0 = start() & u;
98 scalar this1 = end() & u;
99 bool thisOrder = this0 < this1;
101 scalar minThis = min(this0, this1);
102 scalar maxThis = max(this1, this0);
103 const point2D& minThisPt = (thisOrder ? start() : end());
104 const point2D& maxThisPt = (thisOrder ? end() : start());
106 if (maxEdge < minThis)
108 // edge completely below *this
112 else if (maxEdge < maxThis)
114 // maxEdge inside interval of *this
116 thisPt = nearestDist(edgePt).rawPoint();
120 // maxEdge outside. Check if minEdge inside.
121 if (minEdge < minThis)
123 // Edge completely envelops this. Take any this point and
124 // determine nearest on edge.
126 edgePt = e.nearestDist(thisPt).rawPoint();
128 else if (minEdge < maxThis)
130 // minEdge inside this interval.
132 thisPt = nearestDist(edgePt).rawPoint();
136 // minEdge outside this interval
143 return Foam::mag(thisPt - edgePt);
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 } // End namespace Foam
151 // ************************************************************************* //