# Getting a coordinate through a spline with length defined

Through other software I managed to obtain a spline with length of 200mm.

The points would be these:

pts = {{0, 0}, {45, 10}, {75, -15}, {130, -20}, {180, -33.25904718}}


The last value in Y (-33.25904718) is not accurate for this directly depends on the length of the spline, that is 200.

1. I get this value in the SolidWorks software, but how can I get this value using Mathematica?

And another question:

1. There is only one solution or there may be several other?

EDIT :

Through the comments of Michael E2 I think the answer is this documentation, but I couldn't find a way in which the length of the BSpline is an input.

BSpline->Applications->Interpolation

Assuming solving for the final y-coordinate is sought, which is what it sounds like:

len[y_?NumericQ] :=
With[{spl = Interpolation[
{{0, 0}, {45, 10}, {75, -15}, {130, -20}, {180, y}},
Method -> "Spline"]},
NIntegrate[Sqrt[1 + spl'[t]^2], {t, 0, 180}]]


Check OP's solution

len[-33.25904873]
(*  205.858  *)


Try to find a better one:

FindRoot[len[y] == 200, {y, 0}]
len[y] /. %


FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function.... >>

(*
{y -> -15.8953}
202.674
*)


The answer to question 2 is that, yes, there could be more than one solution, but, in fact, there is not even one:

Plot[len[y], {y, -33, 0},
GridLines -> {None, {200}},  PlotRange -> {200, 205}]


Update --

Here's the B-spline example from the docs (pointed out by the OP) adapted to the OP's problem. It still shows it is impossible. Someone either will have to guess the correct basis, or perhaps the OP can find a suitable one.

ClearAll[len];
bs[y_?NumericQ] := Module[{pts, dist, param, knots, m, ctrlpts},
pts = {{0, 0}, {45, 10}, {75, -15}, {130, -20}, {180, y}};
dist =
Accumulate[
Table[EuclideanDistance[pts[[i]], pts[[i + 1]]], {i, Length[pts] - 1}]];
param = N[Prepend[dist/Last[dist], 0]];
knots = {0, 0, 0, 0, 1/3, 2/3, 1, 1, 1, 1};
m = Table[
BSplineBasis[{3, knots}, j - 1, param[[i]]], {i, Length@param}, {j, 6}];
ctrlpts = LinearSolve[m, pts];
BSplineFunction[ctrlpts]
];
len[y_?NumericQ] := NIntegrate[Norm[D[bs[y][t], t]], {t, 0, 1}];


Solution:

splsol = FindRoot[len[y] == 200, {{y, 0}}]
len[y] /. splsol
(*
{y -> -17.3114}
201.19
*)

• It is not necessary to obtain exactly one spline, could be a polynomial of fourth degree. Aug 5, 2016 at 14:27
• @LeandroMacieldeCarvalho With InterpolationOrder -> 4, the length is longer. With InterpolationOrder -> 2, there are two solutions, {y -> -39.7079} and {y -> -0.77588}. Aug 5, 2016 at 14:36
• I made a new calculation in other software and got another value for y. Now I updated the question. Aug 5, 2016 at 14:45
• @LeandroMacieldeCarvalho What is their spline method? Aug 5, 2016 at 14:47
• Another thing I did was to change the Method for Hermite with the new value for Y. The result was closer. Aug 5, 2016 at 14:47