1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 void PolyLine::getStencil(double l
, int &i1
, int &i2
, double &w1
, double &w2
)
29 i1
= m_Points
.size() - 2;
30 i2
= m_Points
.size() - 1;
31 for (int i
= 1; i
< m_Points
.size(); ++i
) {
32 double dL
= (m_Points
[i
] - m_Points
[i
-1]).abs();
33 if (l
>= L
&& l
<= L
+ dL
) {
44 vec3_t
PolyLine::position(double l
)
48 getStencil(l
, i1
, i2
, w1
, w2
);
49 return w1
*m_Points
[i1
] + w2
*m_Points
[i2
];
52 vec3_t
PolyLine::normal(double l
)
56 getStencil(l
, i1
, i2
, w1
, w2
);
57 vec3_t n
= m_Points
[i2
] - m_Points
[i1
];
62 vec3_t
PolyLine::intersection(vec3_t x
, vec3_t n
)
64 double min_err
= EG_LARGE_REAL
;
66 for (int i
= 1; i
< m_Points
.size(); ++i
) {
67 double k
= GeometryTools::intersection(m_Points
[i
-1], m_Points
[i
] - m_Points
[i
-1], x
, n
);
68 double err
= fabs(k
- 0.5);
71 x_best
= (1-k
)*m_Points
[i
-1] + k
*m_Points
[i
];