8

Bug introduced in 10.0.0 and fixed in 10.2


When I enter the following command, half of the fourth-degree spline is missing from the graph (i.e. it doesn't touch the last point). Is this a bug in Mathematica or am I fundamentally misunderstanding something about Bézier curves?

Manipulate[
 Graphics[{BezierCurve[pts, SplineDegree -> 4], Dashed, Green, 
 Line[pts]}, PlotRange -> {{-.5, 1.5}, {-.5, 1.5}}, 
 Frame -> True], {{pts, {{0, 0}, {.5, 0}, {.5, .5}, {1, .5}, {1, 
 1}}}, Locator, LocatorAutoCreate -> True}]

Here's a screenshot of the output: missing part of fourth-degree Bézier curve

What makes me suspicious is that the same behavior shows up in Mathematica's own help file on BezierCurve.

screenshot of mathematica's help files on BezierCurve

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
mimuller
  • 328
  • 1
  • 8
  • 1
    This is probably a bug, cause on V10.1 on Win10 it shows the full curve as expected. – EventHorizon511 Aug 08 '15 at 17:00
  • 1
    It seems to be a bug. This behavior does not occur in Mathematica 9.0.1 or 8.0.4 running on Windows. As such, it would be very helpful if you would state in the question your OS platform and the version of Mathematica you are using. – Oleksandr R. Aug 08 '15 at 17:01
  • Thanks for the feedback! I thought so, but didn't want to claim it was a bug without a second opinion. :) I have Mathematica 10.0.0.0 running on Mac OS X x86. – mimuller Aug 08 '15 at 18:30
  • 1
    I see the same on OS X with version 10.1 - in fact, the bug seems to persist for all degrees above the default 3. So I've added the bugs tag. – Jens Aug 08 '15 at 22:02
  • 1
    It works in V10.2 (Mac OSX). – Michael E2 Aug 08 '15 at 23:13
  • 1
    In Linux I get whole curve in all Mathematica versions I have available: 8, 9, 10.0, 10.1, 10.2, so it seems this bug is OS specific. – jkuczm Aug 12 '15 at 09:50

1 Answers1

8

Since there is really something wrong with the BezierCurve, I made this work-around:

Clear[bezierCurve];

bezierCurve[pts_] := 
 First@ParametricPlot[
   BezierFunction[pts, SplineDegree -> Length[pts] - 1][t], {t, 0, 1}]

Manipulate[
 Graphics[{bezierCurve[pts], Dashed, Green, Line[pts]}, 
  PlotRange -> {{-.5, 1.5}, {-.5, 1.5}}, 
  Frame -> True], {{pts, {{0, 0}, {.5, 0}, {.5, .5}, {1, .5}, {1, 
     1}}}, Locator, LocatorAutoCreate -> True}]

Since the spline degree is always one less than the length of the point list, I didn't adhere to the built-in syntax where the degree is specified separately through an option. I just let the function bezierCurve compute the appropriate degree automatically, to reduce the potential for error.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • Thanks! I just ended up hard-coding it by looking up the formulas in wikipedia. Your approach is certainly more elegant. :) – mimuller Aug 08 '15 at 22:49