A few months ago, I asked a question about the implementation of Bezier surface. Please see here for a full detail.
I also know that BezierFunction[]
is built-in in Wolfram Language.
BezierFunction
[array]represents a Bézier function for a surface or high-dimensional manifold.
Owing to that I have been learning the NURBS theory, and I have implemented a variety of algorithms in my package CAGD
.
Here, thanks for J.M.'s explanation about the definition of high-dimensional Bezier function.
So I implemented the CAGDBezierFunction[]
as follows:
CAGDBezierFunction[array_, dim_][args__] :=
Fold[
#2.#1 &, array,
BernsteinBasis[#1, Range[0, #1], #2] & @@@ Thread@{dim, {args}}]
CAGDBezierFunction[array_] :=
CAGDBezierFunction[array, Most@Dimensions[array] - 1]
pts = RandomReal[1, {10, 10, 2, 1}];
BezierFunction[pts][0.1, 0.2, 0.2]
CAGDBezierFunction[pts][0.1, 0.2, 0.2]
(*{0.701598}*)
However, when I visualize this function via ContourPlot3D[]
, it is very time-consuming.
f = BezierFunction[pts]
ContourPlot3D[f[u, v, w], {u, 0, 1}, {v, 0, 1}, {w, 0, 1}, Mesh -> None] // AbsoluteTiming
ContourPlot3D[
CAGDBezierFunction[pts, {9, 9, 1}][u, v, w],
{u, 0, 1}, {v, 0, 1}, {w, 0, 1}, Mesh -> None]
So my question is :
- Is it possible to optimize the user-defined function
CAGDBezierFunction[]
? Is the programming language of Mathematica a high performance language?
Update:
Thanks for bill s's suggestion: PlotPoints -> 3
Evaluated -> True
in your secondContourPlot3D
? $\endgroup$PlotPoints -> 3
speeds it up by a factor of about 20. $\endgroup$