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

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by