3rd Homework

1. Write a function for knot insertion algorithm. Try it  out for a B-Spline curve (Subscript[c, 1]) of degree 3 with the control points pts and knot vector knots. 
a) Find the point (Subscript[c, 1])(5) on the curve  (Subscript[c, 1]) (using the knot insertion algorithm).
b) Plot a tangent line at the point (Subscript[c, 1])(5) (using the knot insertion algorithm).

knots={0,0,0,0,1,2,4,6,6,6,6};
pts={{0,-3},{1,-2},{0.5,-1},{-1,-1},{-6,1},{-3,4},{1,3}};

c1=Sum[pts[[i+1]]*BSplineBasis[{3, knots},i,t],{i,0,6}];
Show[ParametricPlot[c1,{t,0,6},PlotRange->All],Graphics@Point[c1/.{t->5}]]

2. Find control points and weights of one sixth of a circle (Subscript[c, 2]), such that  (Subscript[c, 2])(0) = {3,0}, (Subscript[c, 2])(1) = {(3/2),((3(Sqrt[3]))/2)} a (Subscript[c, 2])((π/4)) = {(3/(Sqrt[2])),(3/(Sqrt[2]))}.

3. Write a function for rational DeCasteljau algorithm. Find the point (Subscript[c, 2])((π/4)) and plot the tangent line at this point.

4. Using a NURBS curve inscribe a circle into a regular pentagon. (Find control points, weights and a knot vector and plot the result.)

5. Interpolate by biarcs a curve (Subscript[c, 3])={((-t+(t^2))/(1+(t^2))),((3-2 (t^2)+(t^3))/(2+(t^2)))}, t ∈ (-1,1). (pdf “Lagrangeova a Hermitova interpolace”). Split the interval into two subintervals and find the biarc interpolation for each of them. Plot the result.

c3={(t^2-t)/(t^2+1),(t^3-2t^2+3)/(t^2+2)};
pc3=ParametricPlot[c3,{t,-1,1}]

6. Plot a Bezier surface of degrees (2,3) given by the following control mesh:

mesh={{{0,0,2},{3.1,0.5,3},{4.5,0,2}},{{-0.5,1.75,3},{1,2,-1},{5.2,2.25,3}},{{1,4.2,2},{2,3.8,4},{3,4,2}},{{-0.1,6.5,0},{3.2,6.2,2},{5.3,5.8,1}}};

mplot=Show[Graphics3D[{Blue,Thick,Table[Line[mesh[[i]]],{i,1,4}]}],
Graphics3D[{Green, Thick,Table[Line[mesh[[All,i]]],{i,1,3}]}],
Graphics3D[{PointSize[0.02],Point[Flatten[mesh,1]]}]
]

7. Plot a NURBS surface of degrees (2,2) given by the control mesh mesh2 a and weights weights. Use some knot vectors U and  V so that the surface is clamped.

mesh2={{{0,0,2},{3.1,0.5,3},{4.5,0,2},{7,-0.2,3}},{{-0.5,1.75,3},{1,2,-1},{5.2,2.25,3},{6.8,2,4}},{{1,4.2,2},{2,3.8,4},{3,4,2},{4.5,3.9,3}},{{-0.1,6.5,0},{3.2,6.2,2},{5.3,5.8,1},{7.3,6,-1}},{{1.2,8,-1},{3.8,7.7,0},{6,8.1,1},{6.8,7.9,0}}};
weights={{2,1,2,2},{3,4,1,4},{2,6,2,3},{2,3,4,1},{4,3,5,1}};

mplot2=Show[Graphics3D[{Blue,Thick,Table[Line[mesh2[[i]]],{i,1,5}]}],
Graphics3D[{Green,Thick,Table[Line[mesh2[[All,i]]],{i,1,4}]}],
Table[Graphics3D[{PointSize[(Flatten[weights][[i]])*0.01],Point[Flatten[mesh2,1][[i]]]}],{i,1,20}]
]

8.  Write a function for the “four-point subdivision scheme” algorithm for a planar curve. Try several iterations for a curve c which is a regular pentagon.