As I could swear this worked just yesterday, I am probably just doing something stupid here and I am sorry to bother you :)
I am trying to find the point where a curve crosses a line. In this case, the curve is a box, but it should work for other things, too, so I need to find the problem here, not better ways for a solution for boxes.
boxCurve[boundaries_List] := Module[{b = boundaries, bH, bW, cf},
bH = b[[2, 2]] - b[[2, 1]];
bW = b[[1, 2]] - b[[1, 1]];
cf = 2 bH + 2 bW;
Function[t, Piecewise[{
{{b[[1, 1]] + cf t, b[[2, 1]]}, 0 <= cf t < bW},
{{b[[1, 2]], b[[2, 1]] + (cf t - bW)}, bW <= cf t < bW + bH},
{{b[[1, 2]] - (cf t - bW - bH), b[[2, 2]]},
bW + bH <= cf t < 2 bW + bH},
{{b[[1, 1]], b[[2, 2]] - (cf t - 2 bW - bH)},
2 bW + bH <= cf t < 2 bW + 2 bH}
}, {b[[1, 1]], b[[2, 1]] + bH/4}]]
]
The box does work ParametricPlot[boxCurve[{{-1, 1}, {-1, 1}}][s], {s, 0, 1}]
But, when I am trying to calculate the crossing point
Solve[boxCurve[{{-1, 1}, {-1, 1}}][s] == {-1, 1} + {1, -1} t, {s, t}]
Solve[boxCurve[{{-1, 1}, {-1, 1}}][s] == {-0.9, 1} + {1, -1} t, {s, t}]
Solve[boxCurve[{{-1, 1}, {-1, 1}}][s] == {0, 0} + {1, 0} t, {s, t}]
I get no result, although two of the base points of the lines are already on the box. This is true for both NSolve
and Solve
.
As said I could swear that something like this worked yesterday, because I got conditional expressions depending on s, when I only solved for t.