1

I am trying to find an intersection between a straight line and a BSpline.

The lines:

Manipulate[pts = {p0, p1, p2, {3, 1}};
 c = BSplineFunction[pts];
 d[x_?NumericQ] := c[x][[1]];
 e[x_?NumericQ] := c[x][[2]];
 tang = c[.22999] - c[.23001];
 tanline = {c[.23] + tang*10000, c[.23] - tang*10000};
 pline = {c[.23] + {-tang[[2]]*10000, tang[[1]]*10000}, 
          c[.23] - {-tang[[2]]*10000, tang[[1]]*10000}};
 Graphics[{BezierCurve[pts], Point[c[.23]], 
 Line[tanline], {Blue, Line[pline]}, {Red, Line[{{4, -4}, l1}]}}, 
 PlotRange -> 4], {{p2, {2, 3}}, Locator}, {{p1, {2, 4}}, 
 Locator}, {{p0, {1, 1}}, Locator}, {{l1, {1, 1}}, Locator}]

(The tangent lines are part of the larger problem I'm trying to solve, not strictly related to the intersection problem)

I have read various threads for getting symbolic functions to evaluate numerically, but none of the solutions they've used seem to work.

I've been testing functions using the starting red line, with eq -1.666 x + 2.666

FindRoot[-1.66*d[x] + 2.666 == e[x], {x, .8}]

and

FindRoot[-1.66*N[d[x]][[1]] + 2.667 == d[x][[2]], {x, 2}]

And various other things that also failed similarly. Short of implementing the numerical solve myself, what can I do? Am I misusing NumericQ?

A.j.
  • 11
  • 2
  • If you must work with the components, you might have to fall back on the explicit representation in terms of either BernsteinBasis[] or BSplineBasis[] (you had me confused because you were using B-splines in one part and Béziers in another). See e.g. this thread. – J. M.'s missing motivation Jun 30 '16 at 07:53
  • I'll give the basis functions a go, looks like it will involve a deep dive on the subject. Any insight into why the bsplinefunction has such a distaste for being evaluated like this? – A.j. Jun 30 '16 at 09:23
  • @A.j. Are you sure you can't simplify your example? I think there is a lot of irrelevant information here, and I am not sure that I can pinpoint your actual problem, which may actually have a very simple solution after all, once we get it in focus. As an aside, move the definitions of d and e outside of your Manipulate expression, or they will be continuously re-evaluated. – MarcoB Jun 30 '16 at 14:16

1 Answers1

0

It looks like you need to define a function that requires a numerical argument before it will evaluate:

bsf = BSplineFunction[{{1, 1}, {2, 3}, {3, 2}, {3, 1}}];

fun1[t_] := bsf[t][[1]]
fun2[t_?NumericQ] := bsf[t][[1]]

FindRoot[#[t] == 2, {t, .3}] & /@ {fun1, fun2}

Output:

{{t -> 2.}, {t -> 0.347296}}
mef
  • 1,629
  • 11
  • 15