Fix tangent lines for spline Assitant
This change attempts to eliminate tangent line generation and and eliminate most inner connecting lines (In some rare cases the tangent show however not as bad as before.) This is a proof of concept applied to splineAssistant.
originally outside tangent lines can be eliminated by decreasing the step size for the minimum search from 1e-3
to 1e-5
, however this is terribly inefficient doing 100000 function evaluations just to select the minimum. I opted to change this to use Golden Section Search, this method is best suited for global minima search but can be used in this case by subdividing the search space, since the distance problem can have more than one local minima. Each search do 21 evaluations to get a confidence of 1e-6, and while we could get away with 3 division I do 5 to be extra sure we get the true closest with no more than 120 evaluations, from the 1000 we did originally.
To avoid jumping between regions, overlapped lines or closer regions than the start, this implementation only searchs for neighboring solutions when the strokeBegin
point does not change. This approach could be adapted to other assistants, however I haven't looked the others since spline had the most troubles. Below I attach a video showing to the left the original behavior, in which overlapping lines would cause jumping, and to the right the current implementation.