www.gusucode.com > pde 案例源码 matlab代码程序 > pde/CreateCSGGeometryAtTheCommandLineExample.m

    %% Create CSG Geometry at the Command Line
%% Create Basic Shapes
rect1 = [3
    4
    -1
    1
    1
    -1
    0
    0
    -0.5
    -0.5];
C1 = [1
    1
    -0.25
    0.25];
C2 = [1
    -1
    -0.25
    0.25];
% Append extra zeros to the circles
% so they have the same number of rows as the rectangle
C1 = [C1;zeros(length(rect1) - length(C1),1)];
C2 = [C2;zeros(length(rect1) - length(C2),1)];
% Combine the shapes into one matrix
gd = [rect1,C1,C2];
%% Create Names for the Basic Shapes
% Give names for the three shapes
ns = char('rect1','C1','C2');
ns = ns';
%% Set Formula
% Specify the union of the rectangle and C1, and subtract C2
sf = '(rect1+C1)-C2';
%% Create Geometry and Remove Face Boundaries
[dl,bt] = decsg(gd,sf,ns); % combines the basic shapes using the set formula
%% View the geometry with and without boundary removal
pdegplot(dl,'EdgeLabels','on','FaceLabels','on')
xlim([-1.5,1.5])
axis equal
%% Remove the face boundaries
[dl2,bt2] = csgdel(dl,bt); % removes face boundaries
figure
pdegplot(dl2,'EdgeLabels','on','FaceLabels','on')
xlim([-1.5,1.5])
axis equal