making a connectivity array for an ellipse based of rectangles and traingles

2 ビュー (過去 30 日間)
Saim Ehtesham
Saim Ehtesham 2022 年 12 月 1 日
コメント済み: Saim Ehtesham 2022 年 12 月 5 日
I have the following code:
clear all
close all
clc
n = 3; % number of divisions on the boundary
x1 = linspace(0,2,n);
y1_x1 = sqrt(1-( (x1.^2)/4 ) );
y2_x1 = -sqrt(1-( (x1.^2)/4 ) );
x2 = linspace(0,-2,n);
y1_x2 = sqrt(1-( (x2.^2)/4 ) );
y2_x2 = -sqrt(1-( (x2.^2)/4 ) );
X1 = repelem(x1,[n:-1:1]);
X2 = repelem(x2,[n:-1:1]);
Y1_X1 = [];
for i = 1:n
Y1_X1 = [Y1_X1, y1_x1(i:end)]; % concatenate
end
Y2_X1 = [];
for i = 1:n
Y2_X1 = [Y2_X1, y2_x1(i:end)]; % concatenate
end
Y1_X2 = [];
for i = 1:n
Y1_X2 = [Y1_X2, y1_x2(i:end)]; % concatenate
end
Y2_X2 = [];
for i = 1:n
Y2_X2 = [Y2_X2, y2_x2(i:end)]; % concatenate
end
x = [X1 X1 X2 X2];
y = [Y1_X1 Y2_X1 Y1_X2 Y2_X2];
figure()
scatter(x,y) %shows all points of mesh
Now, I want to assign a number to each point in this ellipse such that a 4xN matrix is formed that has either 4 values (for square elements that are on the inside) and 3 values (for all traingles formed from 3 points on the outside line) with one NaN. For this example, at n = 3, the output connected matrix should look like this:
[1 3 2 NaN
1 4 3 NaN
2 6 5 NaN
2 3 7 6
3 4 8 7
4 9 8 NaN
5 6 10 NaN
6 7 11 10
7 8 12 11
8 9 12 NaN
10 11 13 NaN
11 12 13 NaN]
Here, each row represents a shape, and the numbers in the shape represent the number assigned to its coordinates.
The logic behind numbering the coordinate points is it starts at the lowest point then goes above, but from left end to right end.
And the assembly of the array is such that it starts from the left bottom shape, goes to the right and takes one step upwards (but starts at the left everytime), and the assignment of numebrs within the array is counterclockwise for that shape. The assignment code should be such that it works for any value of n (for example more points would be generated if n is increased from 3 to any larger number in line 4 of initial code).
Can this be done by a loop?
I am attaching a sketch where I show the shapes with encircled numbers and numbers assigned to each point without the encircling.
Hope this helps.
Thanks a lot in advance
Feel free to ask questions.
  1 件のコメント
Matt J
Matt J 2022 年 12 月 1 日
Now, I want to assign a number to each point in this ellipse such that a 4xN matrix is formed that has either 4 values (for square elements that are on the inside) and 3 values (for all traingles formed from 3 points on the outside line) with one NaN.
Wouldn't a cell array be better?

サインインしてコメントする。

採用された回答

Matt J
Matt J 2022 年 12 月 1 日
編集済み: Matt J 2022 年 12 月 1 日
Using spatialgraph2D from this FEX download,
load xymesh
xy=sortrows( unique([x(:),y(:)],'rows'),[2,1] );
x=xy(:,1); y=xy(:,2);
DT=delaunayTriangulation(x,y);
E=DT.edges;
Eb=DT.freeBoundary;
Eint=setdiff(E,Eb,'rows');
fn=@(z) abs(diff(z(Eint),1,2));
keep=xor(fn(x)<1e-6,fn(y)<1e-6);
E=[Eb;Eint(keep,:)];
G=graph(table(E,'Var',{'EndNodes'}));
obj=spatialgraph2D(G,x,y);
mosaic(obj);
[p,IDs]=obj.polyshape;
[~,is]=sortrows( cell2mat( arrayfun(@(z) {max(z.Vertices)},p(:)) ) ,[2,1]);
p=p(is); IDs=IDs(is);
N=numel(p);
out=nan(N,4);
for n=1:N
id=IDs{n}; m=length(id);
out(n,1:m)=id;
end
out=sort(out,2)
out = 12×4
1 2 3 NaN 1 3 4 NaN 2 5 6 NaN 2 3 6 7 3 4 7 8 4 8 9 NaN 5 6 10 NaN 6 7 10 11 7 8 11 12 8 9 12 NaN
  12 件のコメント
Matt J
Matt J 2022 年 12 月 2 日
編集済み: Matt J 2022 年 12 月 2 日
You can get a handle to the label text with findobj. Then, you can modify it or delete it as you wish, e.g.,
mosaic(obj);
ht=findobj(gca,'type','text');
set(ht,'FontSize',12);
Saim Ehtesham
Saim Ehtesham 2022 年 12 月 5 日
Thanks a lot for all the help Matt. As you asked, the purpose of that specific arrangement is to do Finite element analysis on the elliptic area. My partner and I are making the connectivity matrix to multiply the shape functions from a rectangular or square master element but the shape functions are stored counter clockwise, starting from lower left corner to keep a homogenous approach throughout the solution.
Again, thanks for all the help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by