2
$\begingroup$

Let's generate an arbitrary convex domain with smooth boundaries:

Graphics[BSplineCurve[{{1, 4}, {5, 3}, {9, 4}, {5, 5}, {8, 7}}, 
  SplineClosed -> True]]

enter image description here

I'd like to discretize the boundary and calculate the perpendicular distances from each point to the corresponding points across the boundary of the domain. Like in the following picture:

enter image description here

At first I thought it should be simple but after some time I couldn't come up with a proper solution. How would you do that? I'd appreciate any help!

$\endgroup$
2
  • $\begingroup$ are the curves always parametric (as opposed to implicit) ? $\endgroup$
    – andre314
    Feb 5, 2019 at 18:44
  • $\begingroup$ No, it can be implicit as well. I used parametric points just for the representation. $\endgroup$ Feb 5, 2019 at 19:35

1 Answer 1

4
$\begingroup$
bsf = BSplineFunction[{{1, 4}, {5, 3}, {9, 4}, {5, 5}, {8, 7}}, SplineClosed -> True]; 
line = Cases[ParametricPlot[bsf[t], {t, 0, 1}] [[1]], _Line, All][[1]]; 

mesh = Range[0, 1, .1];
coords = Nearest[RegionIntersection[line, 
       InfiniteLine[{bsf[#], (bsf[#] + Cross[bsf'[#]])}]][[1]]][bsf[#], 2] & /@ mesh; 

ParametricPlot[bsf[t], {t, 0, 1}, 
 Frame -> True, ImageSize -> Large, Axes -> False, PlotRangePadding -> 1, AspectRatio -> 1,
 Epilog -> {Arrowheads[.03], {RandomColor[], Dynamic@
  Text[Style[Round[#[[1]], .1], 14, Darker@CurrentValue["Color"]],
     #[[1]], {-1.2, 0}, Subtract@@#],
  PointSize[Large], Point[#[[1]]], Thick, Arrow@#} & /@ coords}]

enter image description here

Note: This is too slow to work interactively.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.