#Header Begins--Do not remove##################################################
#
# Maple code to compute uniform cubic B-spline basis and that
# demonstrates the continuity properties of cubic B-spline segments.
#
# (c) Eugene Fiume, University of Toronto, 1995.
#
# You are permitted to use this code for noncommercial, educational
# purposes only. This header must not be removed from this file.
#
#Header Ends--Do not remove####################################################
with(linalg):
MB := matrix( [ [-1/6, 3/6, -3/6, 1/6],
[ 3/6, -6/6, 3/6, 0],
[-3/6, 0, 3/6, 0],
[ 1/6, 4/6, 1/6, 0]
]):
T := [t^3, t^2, t, 1]:
#
# Maple has brain dead matrix-vector multiplication.
# This procedure computes VM, where V is a 1-by-n row vector and
# M is an n-by-m matrix.
#
mult := proc(V,M)
local i;
seq(dotprod(V,col(M, i)), i=1..coldim(M));
end:
V0 := [P0, P1, P2, P3]:
V1 := [P1, P2, P3, P4]:
#
# First compute the basis functions.
#
BSP := mult(T,MB):
print(`The uniform cubic basis functions are:`);
print(BSP);
plot({BSP}, t=0..1);
#
# Now verify continuity.
#
p0 := dotprod([BSP],V0):
p1 := dotprod([BSP],V1):
print(`Data values for first curve segment:`);
print(V0);
print(`Data values for second curve segment:`);
print(V1);
print(`First curve segment at t=1:`);
subs(t=1,p0);
print(`Second curve segment at t=0:`);
subs(t=0,p1);
dp0 := diff(p0,t):
dp1 := diff(p1,t):
print(`First derivative of first curve segment at t=1:`);
subs(t=1,dp0);
print(`First derivative of second curve segment at t=0:`);
subs(t=0,dp1);
ddp0 := diff(dp0,t):
ddp1 := diff(dp1,t):
print(`Second derivative of first curve segment at t=1:`);
subs(t=1,ddp0);
print(`Second derivative of second curve segment at t=0:`);
subs(t=0,ddp1);