1
$\begingroup$

Problem

I'm trying to make a MeshRegion from a bezier surface defined from an array of control points. Consider

bez = BezierFunction[{{{0,0,0},{0,1,0}},{{1,0,0},{1,1,1}}}] ParametricRegion[bez[u,v],{{u,0,1},{v,0,1}}] 

This doesn't work because ParametricRegion requires a triple of functions rather than a function that produces triples. So

ParametricRegion[{bez[u,v][[1]],bez[u,v][[2]],bez[u,v][[3]]},{{u,0,1},{v,0,1}}] 

is the natural next step. This doesn't work because bez[u,v][[1]] evaluates to u etc.

Perhaps some combo of Hold, Inactive or Unevaluated will help, but I can't get them to work.

The answer to "Don't understand an evaluation with BezierFunction" indicates that

f[u_,v_]:=bez[u,v] ParametricRegion[{f[u,v][[1]],f[u,v][[2]],f[u,v][[3]]},{{u,0,1},{v,0,1}}] 

might work, but this fails too. I even tried doing a separate f1[u_,v_]:=bez[u,v][[1]] and so on for 2 and 3, but this failed as well.

My Mathematica $Version is 12.1.1.

Question

How can I feed a BezierFunction into ParametricRegion, minding these problems of defining a triple of functions and evaluation order?


Accepted Answer

@lericr points out that DiscretizeGraphics applied to ParametricPlot produces a good mesh region.

I don't know why why ParametricPlot produces a mesh while ParametricRegion and DiscretizeRegion do not. Further investigations might use TracePrint to figure out details .

$\endgroup$

2 Answers 2

3
$\begingroup$

Not quite what you asked for, but I'd go about it like this:

bez = BezierFunction[{{{0, 0, 0}, {0, 1, 0}}, {{1, 0, 0}, {1, 1, 1}}}]; (* Note the extra braces in the above compared to what you provided. *) ParametricPlot3D[bez[u, v], {u, 0, 1}, {v, 0, 1}] 

enter image description here

DiscretizeGraphics[%] 

enter image description here

$\endgroup$
1
  • $\begingroup$ I fixed the argument to BezierFunction, thanks for catching that. The question stands though; ParametricRegion doesn't play nice. I forgot that DiscretizeGraphics is so powerful! $\endgroup$ Commented Mar 10 at 14:15
1
$\begingroup$

One way to get a MeshRegion from a bezier surface is "doing it by hand". That means, getting the coordinates of points on the surface, that define triangles. Note that MeshRegion wants a list of coordinates and as second argument, the indices of the coordinates that define the triangles.

Here is an example where we define n==10 triangles in the directions u and v:

n = 10; cor = Flatten[Table[bez[u, v], {u, 0, 1, 1/n}, {v, 0, 1, 1/n}], 1]; ind = Table[{Triangle[{i, i + 1, i + 1 + (n + 1) j}], Triangle[{i, i + (n + 1) j, i + 1 + (n + 1) j}]}, {i, n - 1}, {j, n - 1}] // Flatten[#, 1] &; reg = MeshRegion[cor, ind] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.