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

2 Ansichten (letzte 30 Tage)
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 Kommentar
Matt J
Matt J am 1 Dez. 2022
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 1 Dez. 2022
Bearbeitet: Matt J am 1 Dez. 2022
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 Kommentare
Matt J
Matt J am 2 Dez. 2022
Bearbeitet: Matt J am 2 Dez. 2022
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 am 5 Dez. 2022
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by