There are lots of basic graphic-primitives in Mathematica, such as 2D- primitive: Line[], Circle[], Disk[]
and 3D-primitive: Cylinder[], BSplineSurface[], Sphere[], Cuboid[]
,etc.
In general, they own the following basic usage if memory serves:
Graphics(*Graphics3D*)[
{primitiveStyle1, primitive1[arg1],
primitiveStyle2, primitive2[arg2]}]
Graphics(*Graphics3D*)[
{{primitiveStyle1, primitive1[arg1],
primitiveStyle2, primitive2[arg2]}}]
where, primitiveStyle
is one/several of the member of Thick, Green
and so on.
For this question, the MSE has owned two similar threads like:
For the first question, Simon Woods has given a good answer for 2D-case. However, the detail about the implementation for the 2D primitive was not described. In addtion, m_goldberg also given a solution with the help of the built-in primitive.
For instance, now I have to create a 3D primitive BezierSurface[]
via the built-in BezierFunction[]
, I tried using UpValues[]
as follows:
BezierSurface /: Graphics3D[BezierSurface[ctrlnets_]] :=
ParametricPlot3D[
BezierFunction[ctrlnets][u, v], {u, 0, 1}, {v, 0, 1}]
Now we have a test
cpts = Table[{i, j, RandomReal[{-1, 1}]}, {i, 5}, {j, 5}];
Graphics3D[BezierSurface[cpts]]
But, for Graphics3D[{BezierSurface[cpts]}]
, it failed:(. I tried to change the UpValues[]
defintion:
BezierSurface /: Graphics3D[{BezierSurface[ctrlnets_]}] :=
ParametricPlot3D[
BezierFunction[ctrlnets][u, v], {u, 0, 1}, {v, 0, 1}]
which gives me TagSetDelayed::tagpos:
error.
For the BSplineSurface[]
, which own many usages
(*basic usage 1*)
Graphics3D[BSplineSurface[cpts]]
(*basic usage 2*)
Graphics3D[{BSplineSurface[cpts]}]
(*adding style*)
Graphics3D[{Pink, EdgeForm[{Thick, Blue}], Specularity[White, 50],
BSplineSurface[cpts]}]
(*adding other primitives*)
Graphics3D[{PointSize[Medium], Blue, Map[Point, cpts],
Pink, BSplineSurface[cpts]}]
(*another usage*)
Graphics3D[{{Blue, Cylinder[]},
{Red, Sphere[{0, 0, 2}]}}]
So my question is:
- how to make user-defined 3D primitive
BezierSurface[]
works like built-inBSplineSurface[]
?
primitiveStyle
is often referred to as a directive. $\endgroup$Directive[g1,g2,...]
, represents a single graphics directive composed of the directivesg1,g2,...
? $\endgroup$BezierSurface[ctrlnets_] := First@ParametricPlot3D[...]
. $\endgroup$BSplineSurface[cpts]
just returns itself, whileBezierSurface[cpts]
returns a lot of 3D points group. $\endgroup$