# Generating a random scribble using BezierCurve won't smooth in 5th point

I'm working on generating a random scribble I'm using the code provided by a Wolfram reference(which I can't link because of 10 rep limitation of two links). This produced well looking scribbles:

Graphics[{AbsoluteThickness, BezierCurve[RandomReal[1, {4, 2}]]}, Background -> None] However, when I try to generate a more complex scribble the next line won't be as smooth as the others:

Graphics[{AbsoluteThickness, BezierCurve[RandomReal[1, {5, 2}]]}, Background -> None] I experience the same issue when the code is expanded to 6 points(I'd link the image but I can only post 2 images because I have less than 10 reputation). How can I make these scribbles look more natural for more than 4 points? I am aware this can be a mathematics consequence of a Bezier parametric function itself, if that's the case, is there any other way to generate natural smooth scribbles with Mathematica? Thanks.

• Try BezierCurve[RandomReal[1, {5, 2}], SplineDegree -> 4] per the docs. If you want smooth, then the degree should be one less than the number of points. – Michael E2 May 8 '17 at 2:24
• There's also BSplineCurve and the spline method of Interpolation: xIF = Interpolation[RandomReal[10, 23], Method -> "Spline"]; yIF = Interpolation[RandomReal[10, 23], Method -> "Spline"]; ParametricPlot[{xIF[t], yIF[t]}, {t, 1, 23}] – Michael E2 May 8 '17 at 2:30
• Try Graphics[{AbsoluteThickness, BezierCurve[Sort@RandomReal[1, {5, 2}]]}, Background -> None] – J42161217 May 8 '17 at 2:45
• @MichaelE2 your first line of code works pretty well, thanks! – Vinícius Aguiar May 8 '17 at 2:52

I think the problem you are having may have to do with the order of the random points... when random, the line wants to zig and zag back and forth. One way around this would be to pick a good order to visit the random points. For example, FindShortestTour finds a good way to traverse the points.

n = 20;
{d, order} = FindShortestTour[r = RandomReal[1, {n, 2}]];
Graphics[{AbsoluteThickness, BezierCurve[r[[Rest[order]]]]},
Background -> None] • While this a good solution to get random scribbles without overlapping(which reduced a little bit the randomness of it), when n = 5 I still get a "hard" line. – Vinícius Aguiar May 8 '17 at 3:03
• Bezier curves have sharp curves -- they are not smooth. So there is no reason to expect a randomly chosen curve to be smooth! – bill s May 8 '17 at 3:10
• The only way to smooth it is by using Michael's code: BezierCurve[RandomReal[1, {5, 2}], SplineDegree -> 4] ? Just for curiosity: The 5th point always gonna be produce a sharp curve? That seems to happen to me. I don't understand all the math behind it. – Vinícius Aguiar May 8 '17 at 3:14

You can sort these random points
here is the unsorted (red line) and the sorted (black) for 15 points

r = RandomReal[{-5, 5}, {15, 2}];
Graphics[{AbsoluteThickness, BezierCurve[Sort@r], Red,
AbsoluteThickness, BezierCurve[r]}, Background -> None] • Similarly to bill's answer, while this a very nice approach to get random scribbles without overlapping lines, when n = 5 I still get a "hard" line. Michael's comment in my question solved well the "hard" line issue. – Vinícius Aguiar May 8 '17 at 3:05