rianshams
(Rian Shams)
December 11, 2017, 4:51am
1
Hello,
Why does the code (shown below) give this error?
Dot::rect: Nonrectangular tensor encountered.
And how might this code be modified to produce the desired plot?
controlPoints = {{0., 1.48195}, {0.151384, 1.49651}, {0.330883, 1.39382}, {0.488076, 1.2461}, {0.575162, 1.06331}, {0.599079, 0.886118}, {0.547864,
0.698224}, {0.46997, 0.542705}, {0.386957, 0.404801}, {0.285357, 0.28673}, {0.314028, -0.0307762}, {0.202299, -0.0181826}, {0., 0.}};
RevolutionPlot3D[BSplineFunction[controlPoints][t], {t, 0, 1}]
Unfortunately BSplineFunction has many shortcomings. It does not honour exact input, it does not obey to PiecewiseExpand, it does not provide the parameterization of BSplineFunction, and now we discover that it does not play well with RevolutionPlot3D. Here is an alternative:
myBSplineFunction[pts_?MatrixQ] :=
Module[{knots, deg},
knots = Rationalize@BSplineFunction[pts][[6, 1]];
deg = BSplineFunction[pts][[3, 1]];
Apply[Function,
List@Sum[
pts[[i + 1]] BSplineBasis[{deg, knots}, i, #], {i, 0,
Length[pts] - 1}]]];
RevolutionPlot3D[
Evaluate[myBSplineFunction[controlPoints][t]], {t, 0, 1}]
It does work, one just has to represent the components seperately - according to the examples in the documentation:
{fx, fy} = BSplineFunction /@ Transpose[controlPoints];
RevolutionPlot3D[{fx[t], fy[t]}, {t, 0, 1}]
rianshams
(Rian Shams)
December 11, 2017, 5:59pm
4
Thank you. This is what I was looking for as it wasn’t immediately obvious to me that the components needed to be separated out. Appreciate the help!
rianshams
(Rian Shams)
December 11, 2017, 6:02pm
5
Thank you! It is unfortunate that BSlpineFunction has some of the shortcomings you address. Yours is a nice modification that preserves the structure of my original answer.
With ParametricPlot we don’t need to separate the components:
ParametricPlot[BSplineFunction[controlPoints][t], {t, 0, 1}]
Here it is RevolutionPlot3D to be blamed more for the inconvenience.
Dear Gianluca,
you are of course right! I should have written “It does work, if one represents …”. And: I like your version of BSplineFunction!
Best regards – Henrik