CSE 477 / G. Farin
Bicubic Bezier  surface derivatives

We show some bicubic Bezier surfaces, using the Mathematica BSplineSurface function. This good for Graphics display, but it does not allow us to compute with these surfaces. Here, the computations involve derivatives

(* a control mesh: *)
bb=Table[{i,j,-i^2/5+i-Sin[2j]},{i,4},{j,4}];

center=Sum[Sum[bb[[i,j]],{i,4}],{j,4}]/16;
Do[bb[[i,j]]=bb[[i,j]]-center,{i,4},{j,4}];
dists=Table[Norm[bb[[i,j]]-center],{i,4},{j,4}];
radius=Max[dists];

init22=bb[[2,2]][[3]];
init21=bb[[2,1]][[3]];
Manipulate[(
bb[[2,2]][[3]]=z22;
bb[[2,1]][[3]]=z21;
netplot=Graphics3D[{PointSize[Large],Red,Map[Point,bb],Gray,Line[bb],Line[Transpose[bb]]}];
surfplot=Graphics3D[{Opacity[0.7],BSplineSurface[bb]}];
Show[{surfplot,netplot},Boxed->False,ViewPoint->{-6,-14,17},PlotRange-> 0.3radius]),{{z22, init22},-5,5},{{z21,init21},-5,5}]

In the next cell, we compute a Bezier surface together with its partials and normal. Bicubic example:

(Subscript[x, u]) =3 ((Subscript[B, 0]^2)(u), ..., (Subscript[B, 2]^2)(u))(({{(Subscript[b, 10])-(Subscript[b, 00]), ⋯, (Subscript[b, 03])-(Subscript[b, 13])}, {⋮, □, ⋮}, {(Subscript[b, 22])-(Subscript[b, 32]), ⋯, (Subscript[b, 23])-(Subscript[b, 33])}}))(({{(Subscript[B, 0]^3)(v)}, {⋮}, {(Subscript[B, 3]^3)(v)}}))  =  3((Subscript[B, 0]^2)(u), ..., (Subscript[B, 2]^2)(u))(({{↓, ⋯, ↓}, {⋮, □, ⋮}, {↓, ⋯, ↓}}))(({{(Subscript[B, 0]^3)(v)}, {⋮}, {(Subscript[B, 3]^3)(v)}}))

	(Subscript[x, v]) = 3((Subscript[B, 0]^3)(u), ..., (Subscript[B, 3]^3)(u))(({{→, ⋯, →}, {⋮, □, ⋮}, {→, ⋯, →}}))(({{(Subscript[B, 0]^2)(v)}, {⋮}, {(Subscript[B, 2]^2)(v)}}))
	
	n = (Subscript[x, u]) ⋀ (Subscript[x, v])

(* a control mesh: *)
bb=Table[{i,j,-i^2/5+i-Sin[2j]},{i,4},{j,4}];

center=Sum[Sum[bb[[i,j]],{i,4}],{j,4}]/16;
Do[bb[[i,j]]=bb[[i,j]]-center,{i,4},{j,4}];
dists=Table[Norm[bb[[i,j]]-center],{i,4},{j,4}];
radius=Max[dists];

surf[u_,v_]:= Sum[Sum[bb[[i,j]]*BernsteinBasis[3,i-1,u]*BernsteinBasis[3,j-1,v],{i,4}],{j,4}];
surfu[u_,v_]:= Sum[Sum[(bb[[i+1,j]]-bb[[i,j]])*BernsteinBasis[2,i-1,u]*BernsteinBasis[3,j-1,v],{i,3}],{j,4}];
surfv[u_,v_]:= Sum[Sum[(bb[[i,j+1]]-bb[[i,j]])*BernsteinBasis[3,i-1,u]*BernsteinBasis[2,j-1,v],{i,4}],{j,3}];
normal[u_,v_]:=Cross[surfu[u,v],surfv[u,v]];

netplot=Graphics3D[{PointSize[Large],Red,Map[Point,bb],Gray,Line[bb],Line[Transpose[bb]]}];
surfplot=Graphics3D[{Opacity[0.8],Orange,BSplineSurface[bb]}];
partialu[u_,v_]:=Graphics3D[{Thick,Green,{Arrowheads[Large],Arrow[{surf[u,v],surf[u,v]+surfu[u,v]}]}}];
partialv[u_,v_]:=Graphics3D[{Thick,Green,{Arrowheads[Large],Arrow[{surf[u,v],surf[u,v]+surfv[u,v]}]}}];
normalplot[u_,v_]:=Graphics3D[{Thick,Red,{Arrowheads[Large],Arrow[{surf[u,v],surf[u,v]+normal[u,v]}]}}];

tplane[u_,v_]:=Graphics3D[{Opacity[0.9],Brown,Polygon[{surf[u,v]+0.5surfu[u,v]+0.5surfv[u,v],surf[u,v]-0.5surfu[u,v]+0.5surfv[u,v],surf[u,v]-0.5surfu[u,v]-0.5surfv[u,v],surf[u,v]+0.5surfu[u,v]-0.5surfv[u,v]}]}];

Manipulate[(

Show[{surfplot,(*netplot,*) partialu[u,v],partialv[u,v],tplane[u,v],normalplot[u,v]},Boxed->False,ViewPoint->{-6,-4,7},PlotRange-> 0.3radius]),{u,0,1},{v,0,1}]