Plot a Honeycomb Contour

조회 수: 8 (최근 30일)
Juan Navarro
Juan Navarro 2023년 6월 22일
답변: Vandit 2023년 8월 23일
I need to create the contour of an irregular Honeycomb with Nx x Ny unit cells and wall thickness th. All I need are the x,y coordinates of the endpoints describing the contour and their connectivity.
So far I have the x,y coordinates of the endpoints describing the lines in the center of the Honeycomb and their corresponding connectivity. I modified the code found in Drawing honey comb structure by matlab
Any help is very much appreciated!
clc
close all
clear
format long g
%% Control Parameters
L = 7;
Nx = 4; % Number of unit cells in the horizontal direction
Ny = 2; % Number of pair of unit cells in the vertical direction
Th = 2; % Thickness of the walls
%% Generating Honeycomb Topology
[nodes,elems] = CreateHoneycombTopology(L,Nx,Ny);
nodes(30,2:3) = [nodes(30,2)+2,nodes(30,3)-1]; % Adding localized imperfection
%%
r = Th/(2*sind(60));
znodes = [];
zelems = [];
nid = 0;
nel = 0;
angles = [];
for cont1 = 1:size(elems,1)
x1 = nodes(elems(cont1,2),2);
x2 = nodes(elems(cont1,3),2);
y1 = nodes(elems(cont1,2),3);
y2 = nodes(elems(cont1,3),3);
dx = x2-x1;
dy = y2-y1;
phi = atan2d(dy,dx);
angles = [angles;phi];
nx1 = x1+r*cosd(phi-60);
ny1 = y1+r*sind(phi-60);
mx1 = x1+r*cosd(phi+60);
my1 = y1+r*sind(phi+60);
nx2 = x2+r*cosd(phi+240);
ny2 = y2+r*sind(phi+240);
mx2 = x2+r*cosd(phi+120);
my2 = y2+r*sind(phi+120);
nid = nid+1;
znodes = [znodes;nid,nx1,ny1,nx2,ny2,mx1,my1,mx2,my2];
end
%%
% figure
hold on
for cont1 = 1:size(znodes,1)
plot(znodes(cont1,[2,4]),znodes(cont1,[3,5]),'b-')
plot(znodes(cont1,[6,8]),znodes(cont1,[7,9]),'m--')
end
axis equal
axis padded
%% Function to create Honeycomb Topology
function [nodes,elems] = CreateHoneycombTopology(L,Nx,Ny)
%% Generating Walls
X1 = [0:Ny].*3;
X2 = X1+1;
X3 = [-0.5:3:8.5];
X3 = [0:Ny+1].*3-0.5;
X4 = X2+0.5;
nodes = [];
elems = [];
nid = 0;
nel = 0;
for m=0:Nx-1
gap=sqrt(3);
step=[m m]*sqrt(3);
for n=1:length(X1)-1
[nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,[0 0]*gap+step ,[X1(n) X2(n)]);
[nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,[0.5 0.5]*gap+step,[X3(n+1) X4(n)]);
[nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,[0 0.5]*gap+step ,[X2(n) X4(n)]);
[nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,[0 0.5]*gap+step ,[X1(n+1) X3(n+1)]);
[nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,[0.5 1]*gap+step ,[X3(n+1) X1(n+1)]);
[nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,[0.5 1]*gap+step ,[X4(n) X2(n)]);
end
end
for n=1:length(X1)-1
[nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,[1 1]*gap+step,[X1(n) X2(n)]);
end
%% Removing repeated nodes
temp = unique(nodes(:,2:3),'rows');
temp = [[1:size(temp,1)].',temp];
for cont1 = 1:size(elems,1)
id = temp(ismember(temp(:,2:3),nodes(elems(cont1,2),2:3),'rows'),1);
elems(cont1,2) = id;
id = temp(ismember(temp(:,2:3),nodes(elems(cont1,3),2:3),'rows'),1);
elems(cont1,3) = id;
end
nodes = temp;
%% Scaling nodes
nodes(:,2:3) = nodes(:,2:3).*L;
%% Plotting final geometry
if true
figure
hold on
for cont1 = 1:size(elems,1)
plot(nodes(elems(cont1,2:3),2),nodes(elems(cont1,2:3),3),'k:')
axis equal
end
plot(nodes(:,2),nodes(:,3),'ro')
end
end
%% function to add wall to arrays of nodes and elements
function [nodes,elems,nid,nel] = UpdateArrays(nodes,elems,nid,nel,x,y)
x1 = x(1);
x2 = x(2);
y1 = y(1);
y2 = y(2);
nel = nel+1;
nid = nid+1;
nodes = [nodes;nid,x1,y1];
elems = [elems;nel,nid,nid+1];
nid = nid+1;
nodes = [nodes;nid,x2,y2];
end

답변 (1개)

Vandit
Vandit 2023년 8월 23일
Hi,
Kindly add below code snippet to generate the contour of the honeycomb structure and plot it on top of the original honeycomb plot :
%% Generate Contour
contour_x = [];
contour_y = [];
connectivity = [];
for cont1 = 1:size(znodes, 1)
contour_x = [contour_x; znodes(cont1, [2, 4, 6, 8])];
contour_y = [contour_y; znodes(cont1, [3, 5, 7, 9])];
connectivity = [connectivity; [cont1, cont1, cont1, cont1]];
end
%% Plotting
figure
hold on
% Plot original honeycomb structure
for cont1 = 1:size(elems, 1)
plot(nodes(elems(cont1, 2:3), 2), nodes(elems(cont1, 2:3), 3), 'k:')
end
% Plot contour
for cont1 = 1:size(contour_x, 1)
plot(contour_x(cont1, :), contour_y(cont1, :), 'r-')
end
The above mentioned code snippet generates a contour plot by extracting the x and y coordinates from the 'znodes' matrix, which represents modified nodes of a honeycomb structure. The extracted coordinates are stored in 'contour_x' and 'contour_y' matrices, respectively.Then, the code plots the original honeycomb structure as a black dotted line by iterating over the 'elems' matrix. Finally, the code plots the contour by iterating over the ‘contour_x’ matrix. The x and y coordinates of the contour points are extracted and plotted as a red solid line.
The output of the above code snippet is attached below for your reference.
Hope this helps.
Thankyou

카테고리

Help CenterFile Exchange에서 Guidance, Navigation, and Control (GNC)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by