-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluateBasis.m
79 lines (66 loc) · 1.98 KB
/
evaluateBasis.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function [N,dN_du] = evaluateBasis(qPts)
% Element parameters.
n = 3;
nen = 10;
nQPts = size(qPts,1);
N = zeros(nen,nQPts);
dN_du = zeros(nen,3,nQPts);
for qq = 1:nQPts
xi = qPts(qq,1);
eta = qPts(qq,2);
% Find the barycentric coordinates of xi and eta
vert = [0,0;1,0;0,1];
x1 = vert(1,1);
x2 = vert(2,1);
x3 = vert(3,1);
y1 = vert(1,2);
y2 = vert(2,2);
y3 = vert(3,2);
detA = det([x1,x2,x3; y1,y2,y3;1, 1, 1]);
detA1 = det([xi,x2,x3;eta,y2,y3;1, 1, 1]);
detA2 = det([x1,xi,x3;y1,eta,y3;1, 1, 1]);
detA3 = det([x1,x2,xi;y1,y2,eta;1, 1, 1]);
u = detA1/detA;
v = detA2/detA;
w = detA3/detA;
% Tuples is the index in barycentric coordinates of the ith control point.
tuples = [ 3 0 0;...
0 3 0;...
0 0 3;...
2 1 0;...
1 2 0;...
0 2 1;...
0 1 2;...
1 0 2;...
2 0 1;...
1 1 1];
% Loop through the control points.
for nn = 1:nen
i = tuples(nn,1);
j = tuples(nn,2);
k = tuples(nn,3);
% From page 141 of Bezier and B-splines. Calculate the ith basis function
% its derivative with respect to barycentric coordinates.
N(nn,qq) = factorial(n)/...
(factorial(i)*factorial(j)*factorial(k))*u^i*v^j*w^k;
if i-1 < 0
dN_du(nn,1,qq) =0;
else
dN_du(nn,1,qq) = n * factorial(n-1)/...
(factorial(i-1)*factorial(j)*factorial(k))*u^(i-1)*v^j*w^k;
end
if j-1 < 0
dN_du(nn,2,qq) = 0;
else
dN_du(nn,2,qq) = n * factorial(n-1)/...
(factorial(i)*factorial(j-1)*factorial(k))*u^(i)*v^(j-1)*w^k;
end
if k-1 < 0;
dN_du(nn,3,qq) = 0;
else
dN_du(nn,3,qq) = n * factorial(n-1)/...
(factorial(i)*factorial(j)*factorial(k-1))*u^i*v^j*w^(k-1);
end
end
end
return