1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
26 Finds nearest triangle and vertex.
28 \*---------------------------------------------------------------------------*/
30 #include "triSurface.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 int main(int argc, char *argv[])
45 argList::noParallel();
46 argList::validArgs.clear();
47 argList::validOptions.insert("x", "X");
48 argList::validOptions.insert("y", "Y");
49 argList::validOptions.insert("z", "Z");
51 argList::validArgs.append("surface file");
53 argList args(argc, argv);
57 args.optionRead<scalar>("x"),
58 args.optionRead<scalar>("y"),
59 args.optionRead<scalar>("z")
61 Info<< "Looking for nearest face/vertex to " << samplePt << endl;
64 Info<< "Reading surf1 ..." << endl;
65 triSurface surf1(args.additionalArgs()[0]);
71 const pointField& localPoints = surf1.localPoints();
74 scalar minDist = GREAT;
76 forAll(localPoints, pointI)
78 const scalar dist = mag(localPoints[pointI] - samplePt);
86 Info<< "Nearest vertex:" << endl
87 << " index :" << minIndex << " (in localPoints)" << endl
88 << " index :" << surf1.meshPoints()[minIndex]
89 << " (in points)" << endl
90 << " coordinates:" << localPoints[minIndex] << endl
97 const pointField& points = surf1.points();
104 const labelledTri& f = surf1[faceI];
105 const point centre = f.centre(points);
107 const scalar dist = mag(centre - samplePt);
115 const labelledTri& f = surf1[minIndex];
117 Info<< "Face with nearest centre:" << endl
118 << " index :" << minIndex << endl
119 << " centre :" << f.centre(points) << endl
120 << " face :" << f << endl
121 << " vertex coords:" << points[f[0]] << " "
122 << points[f[1]] << " " << points[f[2]] << endl
126 Info << "End\n" << endl;
132 // ************************************************************************* //