Mathematica provides an example of visualizing a Hilbert curve using splines as a Graphics object in this entry in its documentation system.

However, when one attempts to change the thickness, some graphical artifacts are generated (notice the seemingly arbitrarily placed sharp nubs on the main curve). The generating code and image are included below—notice the only difference between this line of code and the code in the documentation center is the argument for the thickness.

Is there a quick way to avoid/get rid of these?

Graphics[{Thickness[50/1500], HilbertCurve[4] /. Line -> BSplineCurve}]

enter image description here

  • 3
    $\begingroup$ See CapForm - either CapForm[None] or CapForm["Round"] fixes the issue $\endgroup$
    – Lukas Lang
    Commented Feb 5, 2020 at 16:03
  • $\begingroup$ My Mathematica 12 for Linux draws the curve without artifacts. I suggest tagging the post as a bug. $\endgroup$
    – aooiiii
    Commented Feb 5, 2020 at 16:07
  • 1
    $\begingroup$ @aooiiii. I don't think there is any bug; just the usual bad behavior that results from not having specified the best end cap form. $\endgroup$
    – m_goldberg
    Commented Feb 6, 2020 at 2:00
  • $\begingroup$ @m_goldberg, shouldn't Mathematica's output be invariant to the operating system it's running on? $\endgroup$
    – aooiiii
    Commented Feb 6, 2020 at 10:43
  • $\begingroup$ @aooiiii. That would be ideal but I suspect the cost in time and money to achieve that goal is prohibitive. $\endgroup$
    – m_goldberg
    Commented Feb 8, 2020 at 2:44

1 Answer 1


I evaluated the OP's code with V12.0 running on MacOS 10.13.4. It reproduced his image as I thought it would. Some of the corners of the default "Square" end caps extend beyond the curve boundary causing the artifacts the OP observed. On the other hand, setting the end caps to None or "Butt" produced voids. So the only form I recommend is:

Graphics[{Thickness[50/1500], CapForm["Round"], HilbertCurve[4] /. Line -> BSplineCurve}]



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.