-
Notifications
You must be signed in to change notification settings - Fork 0
/
igf2d.m
49 lines (47 loc) · 1.6 KB
/
igf2d.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
function nrb=igf2d(id)
switch id
case 1%2D parametric space example: an annulus
%inner and outer radius
ro=2;
ri=1;
%knots
knots=cell(1,2);
knots{1}=[0 0 1 1];
knots{2}=[0 0 0 1 1 2 2 3 3 4 4 4]./4;
%unweighted control points
coefs=zeros(4,2,9);
coefs(1,1,:)=[ri ri 0 -ri -ri -ri 0 ri ri];
coefs(1,2,:)=[ro ro 0 -ro -ro -ro 0 ro ro];
coefs(2,1,:)=[0 ri ri ri 0 -ri -ri -ri 0];
coefs(2,2,:)=[0 ro ro ro 0 -ro -ro -ro 0];
%coefs(3,:,:) all zeros
%weights
coefs(4,1,:)=[1 sqrt(0.5) 1 sqrt(0.5) 1 sqrt(0.5) 1 sqrt(0.5) 1];
coefs(4,2,:)=[1 sqrt(0.5) 1 sqrt(0.5) 1 sqrt(0.5) 1 sqrt(0.5) 1];
%weighted control points
coefs(1,:,:)=coefs(1,:,:).*coefs(4,:,:);
coefs(2,:,:)=coefs(2,:,:).*coefs(4,:,:);
%make an NURBS geometry object
nrb = nrbmak(coefs, knots);
case 2
L=1;
H=1;
%knots
knots=cell(1,2);
knots{1}=[0 0 1 1];
knots{2}=[0 0 1 1];
%unweighted control points
coefs=zeros(4,2,2);
coefs(1,:,:)=[-L/2,L/2;-L/2,L/2];
coefs(2,:,:)=[-L/2,-L/2;L/2,L/2];
coefs(3,:,:)=[0,H;H,0];
%weights
coefs(4,:,:)=[1 1;1 1];
%weighted control points
coefs(1,:,:)=coefs(1,:,:).*coefs(4,:,:);
coefs(2,:,:)=coefs(2,:,:).*coefs(4,:,:);
coefs(3,:,:)=coefs(3,:,:).*coefs(4,:,:);
%make an NURBS geometry object
nrb = nrbmak(coefs, knots);
end
end