concept-collection / numbl-chunkie
numbl-chunkie / chunkie_ex07_interior.m
61 lines · 1.5 KBBlameHistoryRaw
1% Example 7: Find the points on the interior of a (multi-component)
2% chunker domain using chunkerinterior, and visualize them.
4mip load --install magland/magland/chunkie;
6tic;
8% recreate the circle (chnkr1)
9rad = 2; ctr = [1.0;-0.5];
10circfun = @(t) ctr + rad*[cos(t(:).');sin(t(:).')];
11chnkr1 = chunkerfunc(circfun);
13% recreate the random-mode star (chnkr2)
14rng(0)
15modes = randn(11,1); modes(1) = 1.1*sum(abs(modes(2:end)));
16ctr2 = [1.0;-0.5];
17chnkr2 = chunkerfunc(@(t) chnk.curves.bymode(t,modes,ctr2));
19% rebuild the merged domain (chnkr7)
20chnkr5 = chnkr2;
21chnkr5 = chnkr5.rotate(pi/4);
22chnkr5 = chnkr5.reflect(pi/2);
23chnkr5 = chnkr5.reverse();
25chnkr6 = chnkr1;
26A = 0.5*[2 -1; 1 1];
27r1 = [-1;0.5];
28chnkr6 = r1 + A*chnkr6;
29chnkr6 = chnkr6.reverse();
31% recenter the circle inside the star and scale it down so it fits
32mins5 = min(chnkr5); maxs5 = max(chnkr5);
33mins6 = min(chnkr6); maxs6 = max(chnkr6);
34ctr5 = 0.5*(mins5+maxs5);
35ctr6 = 0.5*(mins6+maxs6);
36ext5 = min(maxs5 - mins5);
37ext6 = max(maxs6 - mins6);
38scale = 0.3*ext5/ext6;
39chnkr6 = chnkr6 + (-ctr6);
40chnkr6 = scale*chnkr6;
41chnkr6 = chnkr6 + ctr5;
43chnkr7 = merge([chnkr5,chnkr6]);
45% grid of test points
46mins = min(chnkr7); maxs = max(chnkr7);
47x1 = linspace(mins(1),maxs(1)); y1 = linspace(mins(2),maxs(2));
48[xx,yy] = meshgrid(x1,y1);
49pts = [xx(:).'; yy(:).'];
51% interior test
52in = chunkerinterior(chnkr7,pts);
54zz = nan(size(xx));
55zz(in) = 1;
57toc;
59figure(6)
60h = pcolor(xx,yy,zz); set(h,'EdgeColor','none');
61axis equal tight