7
$\begingroup$

I have an ordered sequence of points along a closed directed planar contour with self-intersections. I need to find a continuous curve interpolating those points and plot it, with small arrowheads showing its direction (preferably, placed at equal intervals along the curve), and color-fill enclosed regions having an odd winding number. Below is a picture I drew manually to explain the idea (it should be more smooth than that). How can I do this in Mathematica? enter image description here

$\endgroup$

1 Answer 1

14
$\begingroup$

Something to get you started:

SeedRandom[10]
pts = RandomReal[{0, 1}, {8, 2}];

int = Interpolation[Thread@{N@Subdivide[0, 1, 8], Append[#, First@#] &@pts}, PeriodicInterpolation -> True, InterpolationOrder -> 100];
line = FirstCase[ParametricPlot[int[x], {x, 0, 1}], _Line, Line@{}, All];
Graphics[
 {
  LightGray,
  FilledCurve@line,
  Black,
  Thick,
  Arrowheads@Append[0]@Table[0.05, 10],
  Arrow@JoinedCurve@line,
  Red,
  AbsolutePointSize@5,
  Point@pts
  }
 ]

enter image description here

The main idea is to use Interpolation with PeriodicInterpolation->True and a high InterpolationOrder to get the boundary. The InterpolatingFunction is then sampled with the help of ParametericPlot to get a smooth look without just blindly sampling hundereds of times.

Finally, the image is built using Arrow and Arrowheads for the perimeter, and FilledCurve for the shading.

$\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.