% B-spline Tutorial % by Ashish Myles (marcianx@gmail.com) % Plot the knots as vertical black dotted/dashed lines, and the control % points and polygon in red. function plot_knots_and_cpts(knots, cpts, draw_flags) hold on; nk = length(knots); deg = nk - length(cpts) - 1; grev = greville(knots, deg); dy = ( max(cpts) - min(cpts) ) * 0.20; range_x = [ min(knots), max(knots) ]; if (deg == 0) range_x = [ 2*knots(1)-knots(2), 2*knots(end)-knots(end-1) ]; end range_y = [ min(cpts)-dy, max(cpts)+dy ]; % Draw the control points if bitand(draw_flags, 1) plot(grev, cpts, 'r*'); plot(grev, cpts, 'ro'); end % Draw the control polygon if bitand(draw_flags, 2) plot(grev, cpts, 'r'); end % Draw the knots if bitand(draw_flags, 4) uknots = unique(knots); mult = histc(knots, sort(uknots)); mult2stipple = { ':', '-.', '--', '-' }; for i = 1:length(uknots) c = strcat('k', mult2stipple{min(mult(i), length(mult2stipple))}); plot([uknots(i), uknots(i)], [range_y(1), range_y(2)], c); end end axis([range_x, range_y]); hold off;