# Poor/wrong sampling in 1D DiscretizeRegion of splines?

Bug introduced in 10.1 and persisting through 10.2 or later and Fixed in 11.3

## Context

In relation to this question I have would like to use splines to define a ParametricRegion and DiscretizeRegion

I proceed as follows:

pts = {{1, 0}, {1.8, 3}, {0, 2}};
{xu, yu} = Transpose[pts];
n = 2;m = Length[pts];
knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n),
ConstantArray[1, n + 1]} // Flatten;
fx[t_] = xu.Table[ BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
fy[t_] = yu.Table[ BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];


So that

ParametricPlot[{fx[t], fy[t]}, {t, 0, 1}, Axes -> None, Frame -> True,
Epilog -> {Directive[AbsolutePointSize, Red], Point[pts]}] Now I would like to Discretize this BSpline as follows:

  dpr = ParametricRegion[{{ fx[t], fy[t]}, 0 <= t <= 1}, t];
δΩ = DiscretizeRegion[dpr, MaxCellMeasure -> 0.001];


This seems to produce a buggy region. Indeed

   Show[δΩ, Axes -> True] presents some defect in the triangulation. Note in particular the two points at the origin and at coordinate (0.9,-0.2).

## Question

Is this a bug in DiscretizeRegion?

Can anyone reproduce this problem?

I am using mathematica 10.1 on macos X.

Thanks!

## Update

In mathematica 10.2 is works better but not always. For instance let us define

Jet0[pts_: {{1, 0}, {1.8, 1.8}, {0, 2}}] :=
Module[{xu, yu, n, m, knots, fx, fy, pr, mesh, t, r},
{xu, yu} = Transpose[pts];
n = 2; m = Length[pts];
knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n),
ConstantArray[1, n + 1]} // Flatten;
fx[t_] =
xu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
fy[t_] =
yu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
pr = ParametricRegion[{{r fx[t], r fy[t]}, 0 <= t <= 1 &&
0 <= r <= 1}, {t, r}];
mesh = ToElementMesh[pr, "MaxBoundaryCellMeasure" -> 0.1];
mesh["Wireframe"]]


so that

Jet0[]


produces but on the other hand

Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}]


produces

\$Failed[Wireframe]

• I can reproduce this on Windows in 10.1 but it has been fixed in 10.2. – RunnyKine Jul 26 '15 at 20:21
• @RunnyKine thanks! Do you think it is the source of my problem in the linked question? Should I retag my question as bug? as 10.1? – chris Jul 26 '15 at 20:27
• I don't think that's the source of the problem. If you can rewrite the ParametricRegion as an ImplicitRegion you may have better chances. For some reason, Mathematica doesn't know how to handle ParametricRegion properly. – RunnyKine Jul 26 '15 at 20:42
• @RunnyKine would you know how to do this? – chris Jul 26 '15 at 21:13
• Including the word "fixed" on the first line is going to make this post disappear from the bug-radar. – Szabolcs Jul 27 '15 at 20:14

DiscretizeRegion will work in place of ToElementMesh:

Jet0[pts_: {{1, 0}, {1.8, 1.8}, {0, 2}}] :=
Module[{xu, yu, n, m, knots, fx, fy, pr, t, r},
{xu, yu} = Transpose[pts];
n = 2; m = Length[pts];
knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n),
ConstantArray[1, n + 1]} // Flatten;
fx[t_] = xu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
fy[t_] = yu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
pr = ParametricRegion[{{r fx[t], r fy[t]}, 0 <= t <= 1 && 0 <= r <= 1},
{t, r}];
DiscretizeRegion[pr, MaxCellMeasure -> {"Length" -> 0.1}]]

Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}] • your answer is useful for people who are happy with DiscretizeRegion. According to @user21 I need ToElementMesh in order to be able to solve a PDE on it. – chris Jul 27 '15 at 20:11
• @chris ToElementMesh@Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}] generally converts a MeshRegion to an ElementMesh with no problem. NDSolve should convert a MeshRegion automatically, too, but often one wants to set up the ElementMesh first before calling NDSolve. (The problem here is getting from a parametric description to any sort of mesh.) – Michael E2 Jul 27 '15 at 20:15
• @chris, Ayy, I forgot there is a difference: Along the boundary, the quadratic vertices in converting a MeshRegion are placed on the linear boundary elements; in converting a Region, they are placed on the Region's boundary and thus are more accurate for solving PDEs. – Michael E2 Jul 27 '15 at 20:45
• @MichaelE2, yes this is quite an important point, For numerics ToElementMesh is preferable. – user21 Jul 28 '15 at 7:12

There is a workaround involving Rationalize.

Jet0[pts0_: {{1, 0}, {1.8, 1.8}, {0, 2}}] :=
Module[{xu, yu, n, m, knots, fx, fy, pr, mesh, t, r},
pts=Rationalize[pts0,0.001];
{xu, yu} = Transpose[pts];
n = 2; m = Length[pts];
knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n),
ConstantArray[1, n + 1]} // Flatten;
fx[t_] =
xu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
fy[t_] =
yu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
pr = ParametricRegion[{{r fx[t], r fy[t]}, -1 <= t <= 1 &&
0 <= r <= 1}, {t, r}];
mesh = ToElementMesh[pr, "MaxBoundaryCellMeasure" -> 0.1];
mesh["Wireframe"]]


works as expected:

 Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}] • I thought the error with BoundaryDiscretizeRegion suggested a numerical issue. +1 – Michael E2 Jul 27 '15 at 20:06