1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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
26 polyLineEdge class : defines a curvedEdge in terms of a series of
27 straight line segments
29 \*---------------------------------------------------------------------------*/
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 // calcDistances generates the distances_ lookup table (cumulative
43 // distance along the line) from the individual vectors to the points
45 void polyLine::calcDistances()
49 for (label i=1; i<distances_.size(); i++)
52 mag(controlPoints_[i] - controlPoints_[i-1])
56 lineLength_ = distances_[distances_.size()-1];
58 for (label i=1; i<distances_.size(); i++)
60 distances_[i] /= lineLength_;
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 polyLine::polyLine(const pointField& ps)
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 vector polyLine::position(const scalar lambda) const
83 // check range of lambda
85 if (lambda < 0 || lambda > 1)
87 FatalErrorIn("polyLine::position(const scalar)")
88 << "Parameter out of range, "
89 << "lambda = " << lambda
93 // Quick calc of endpoints
97 return controlPoints_[0];
99 else if (lambda > 1 - SMALL)
101 return controlPoints_[controlPoints_.size()-1];
105 // search table of cumulative distance to find which linesegment we
112 } while (distances_[i] < lambda);
116 // construct position vector
118 (lambda - distances_[i])
119 /(distances_[i+1] - distances_[i]);
121 vector offsetV = controlPoints_[i+1] - controlPoints_[i];
123 return controlPoints_[i] + offsetDist*offsetV;
127 scalar polyLine::length() const
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 } // End namespace Foam
137 // ************************************************************************* //