concept-collection / numbl-chunkie
numbl-chunkie / chunkie_ex06_combined.m
53 lines · 1.4 KBBlameHistoryRaw
1% Example 6: Combine a transformed copy of a star-shaped domain and a
2% transformed copy of a circle into a single multi-component chunker, with
3% consistent outward-pointing normals.
5mip load --install magland/magland/chunkie;
7tic;
9% recreate the circle (chnkr1)
10rad = 2; ctr = [1.0;-0.5];
11circfun = @(t) ctr + rad*[cos(t(:).');sin(t(:).')];
12chnkr1 = chunkerfunc(circfun);
14% recreate the random-mode star (chnkr2)
15rng(0)
16modes = randn(11,1); modes(1) = 1.1*sum(abs(modes(2:end)));
17ctr2 = [1.0;-0.5];
18chnkr2 = chunkerfunc(@(t) chnk.curves.bymode(t,modes,ctr2));
20% rotate, reflect, and reverse the star
21chnkr5 = chnkr2;
22theta = pi/4;
23chnkr5 = chnkr5.rotate(theta);
24chnkr5 = chnkr5.reflect(pi/2);
25chnkr5 = chnkr5.reverse();
27% affine-transform the circle and reverse its orientation
28chnkr6 = chnkr1;
29A = 0.5*[2 -1; 1 1];
30r1 = [-1;0.5];
31chnkr6 = r1 + A*chnkr6;
32chnkr6 = chnkr6.reverse();
34% recenter the circle inside the star and scale it down so it fits
35mins5 = min(chnkr5); maxs5 = max(chnkr5);
36mins6 = min(chnkr6); maxs6 = max(chnkr6);
37ctr5 = 0.5*(mins5+maxs5);
38ctr6 = 0.5*(mins6+maxs6);
39ext5 = min(maxs5 - mins5);
40ext6 = max(maxs6 - mins6);
41scale = 0.3*ext5/ext6;
42chnkr6 = chnkr6 + (-ctr6);
43chnkr6 = scale*chnkr6;
44chnkr6 = chnkr6 + ctr5;
46% merge into one multi-component domain
47chnkr7 = merge([chnkr5,chnkr6]);
49toc;
51figure(5); clf
52plot(chnkr7,'b-x'); hold on; quiver(chnkr7,'r')
53axis equal tight