| 48 | } |
| 49 | |
| 50 | std::vector<double> LNLib::Interpolation::GetChordParameterization(const std::vector<XYZ>& throughPoints) |
| 51 | { |
| 52 | size_t size = throughPoints.size(); |
| 53 | |
| 54 | if (size == 0) { |
| 55 | return {}; |
| 56 | } |
| 57 | if (size == 1) { |
| 58 | return { 0.0 }; |
| 59 | } |
| 60 | if (size == 2) { |
| 61 | return { 0.0, 1.0 }; |
| 62 | } |
| 63 | |
| 64 | std::vector<double> segmentLengths; |
| 65 | segmentLengths.reserve(size - 1); |
| 66 | double totalLength = 0.0; |
| 67 | |
| 68 | for (size_t i = 1; i < size; ++i) { |
| 69 | double segLen = throughPoints[i].Distance(throughPoints[i - 1]); |
| 70 | segmentLengths.push_back(segLen); |
| 71 | totalLength += segLen; |
| 72 | } |
| 73 | |
| 74 | if (MathUtils::IsAlmostEqualTo(totalLength, 0.0)) { |
| 75 | std::vector<double> uk(size); |
| 76 | for (size_t i = 0; i < size; ++i) { |
| 77 | uk[i] = static_cast<double>(i) / static_cast<double>(size - 1); |
| 78 | } |
| 79 | return uk; |
| 80 | } |
| 81 | |
| 82 | std::vector<double> uk(size); |
| 83 | uk[0] = 0.0; |
| 84 | uk[size - 1] = 1.0; |
| 85 | |
| 86 | double accumulated = 0.0; |
| 87 | for (size_t i = 1; i < size - 1; ++i) { |
| 88 | accumulated += segmentLengths[i - 1]; |
| 89 | uk[i] = accumulated / totalLength; |
| 90 | } |
| 91 | |
| 92 | return uk; |
| 93 | } |
| 94 | |
| 95 | double LNLib::Interpolation::GetCentripetalLength(const std::vector<XYZ>& throughPoints) |
| 96 | { |