对于关于x,y轴对称图形的节点矩阵,用MATLAB的delaunay命令生成的三角网格不能满足有限元分析时——轴对称的条件,如图所示。
请问如何编写程序能使得生成的三角网格也能保持轴对称?
目前正在解决的问题为:
已知1/4平面的坐标点,通过两次对称,生成整张平面,然后将1/4平面的点所生成的三角网格,进行对称连接,最终形成一个关于x=a,和y=b的双轴对称网格。
该回答引用自GPT:
要实现对称的条件,你可以先使用delaunay命令生成三角网格,然后根据节点的坐标和轴对称条件,修改节点的坐标和顶点列表,最后用modifiedDelaunay函数重新生成对称的三角网格。以下是MATLAB代码示例:
假设原始1/4平面中的点坐标为(x0,y0),通过x轴和y轴的对称后,点坐标变为(-x0, y0)和(x0, -y0)。节点的坐标修改后(如下所示),则三角网格就可以保持对称:
%生成原始1/4平面的点坐标
x0 = [1 2 2 1];
y0 = [1 1 2 2];
%对称后的坐标
x_sym = [-x0 x0];
y_sym = [y0 -y0];
%修改节点坐标和顶点列表
node = [(1:length(x0))';(1:length(x0))'+length(x0)];
node_sym = [node; node+length(x0)];
x = [x0 -x0 x0];
y = [y0 y0 -y0];
tri = delaunay(x,y); %生成三角网格
%将顶点列表中的对称三角形下标添加到末尾
tri = [tri; tri+length(node); tri+2*length(node)];
%将对称后的节点坐标添加到结点列表中
node = [node; node_sym];
x = [x x_sym];
y = [y y_sym];
%重新生成对称的三角网格
tri_sym = modifiedDelaunay(node, tri);
%绘制结果
triplot(tri_sym, x, y)
生成的三角网格保证了对称性,你可以用这个程序来解决你的问题。
可以借鉴下
%peaks函数绘制
[X,Y]=meshgrid(-3:0.125:3);%范围
Z=peaks(X,Y);
subplot(1,2,1);
axis([-3 3 -3 3 -10 10]);
mesh(X,Y,Z);
title('三维网线图');
subplot(1,2,2);
meshc(X,Y,Z);
title('三维网线及等高线图');
800379fdfa6d79b3cd864afa06a02a22.png
三维网线效果图
close all, clear all, clc, dbstop if error
[x,y]=meshgrid(1:15,1:15);%格网范围
tri=delaunay(x,y);%以X,Y为准生成Delaunay triangulation(三角网)
z=peaks(15);
subplot(1,2,1),trimesh(tri,x,y,z);%显示三角网线
title('不规则三角网线图');
subplot(1,2,2),trisurf(tri,x,y,z);%显示三角网面
title('不规则三角网面图');
colormap(jet);%颜色,包括hsv等,jet是默认的
brighten(0.6);%亮度
可以参考下面步骤
将初始的1/4平面坐标点进行镜像对称,生成整个平面上的所有点。这可以通过复制原始点到新的坐标位置的方式实现,例如将第一象限中的点$(x,y)$,复制到第二象限中位置$(−x,y)$,第三象限中位置$(−x,−y)$,和第四象限中位置$(x,−y)$,则可以得到整个平面上的所有点。
对于每个生成的点,判断它是否在x=a和y=b的轴上,如果是,将其特殊标记出来,并记录它在轴上的位置。
对于生成的所有点,使用 MATLAB 的 delaunay 命令生成三角网格。选取生成的所有三角形中,包含至少一个标记点的三角形,并将标记点之间的边也加入三角网格中。
针对新生成的三角网格,对于轴上的标记点,分别找到它们在轴上对称的点,将它们之间的边加入到三角网格中。
最终得到的三角网格即为关于x=a和y=b双轴对称的三角网格。
该回答引用ChatGPT4与博主@晓码自在合作编写:
对于关于x,y轴对称的图形,使用MATLAB的delaunay命令生成的三角网格无法满足轴对称条件,需要额外的处理。
可以这样编写程序生成轴对称的三角网格:
具体MATLAB实现如下:
matlab
% 生成节点矩阵
node = [x, y];
% 生成三角网格
tri = delaunay(node(:,1),node(:,2));
% 中点坐标
centerx = mean(node(:,1));
centery = mean(node(:,2));
% 扩充对称节点
node_sym = [node; 2*centerx-node(:,1), node(:,2); ...
node(:,1), 2*centery-node(:,2)];
% 修改三角网格索引
tri_sym = fliplr(tri);
tri_sym(:,1) = tri_sym(:,1) + size(node,1);
tri_sym(:,2) = tri_sym(:,2) + size(node,1);
tri_sym(:,3) = tri_sym(:,3) + size(node,1);
tri_sym = [tri; tri_sym];
% 删除与中线相交的面
del_idx = [];
for i = 1:size(tri_sym,1)
p1 = node_sym(tri_sym(i,1),:);
p2 = node_sym(tri_sym(i,2),:);
p3 = node_sym(tri_sym(i,3),:);
if intersectLineTriangle([centerx,0;centery,0],[p1;p2;p3])
del_idx = [del_idx; i];
end
end
tri_final = tri_sym(setdiff(1:end,del_idx), :);
该程序生成的tri_final三角网格具有x,y轴对称性,满足有限元分析的要求。
要生成轴对称的三角网格,可以在MATLAB中使用PDE Toolbox中的几何建模工具箱。具体步骤如下:
使用PDE Toolbox中的“偏微分方程模型器”创建一个轴对称的几何模型。在模型中加入轴对称的对称轴,并保证模型关于对称轴对称。
将几何模型导出为PDE Toolbox中的几何描述数据格式,即.pdeg文件。
在MATLAB中使用pdegeom函数读取.pdeg文件,并生成轴对称的三角网格。在pdegeom函数中,可以通过设置“Rotations”属性来指定轴对称。
以下是一个示例代码:
matlab
Copy
% 创建一个轴对称的几何模型
model = createpde();
geometryFromEdges(model,@circleg);
model = pdecirc(model,'C1');
model = pderect(model,-1,1,-1,1);
set(model,'Axisymmetric','on');
% 导出几何描述数据
generateMesh(model,'Hmax',0.1);
[p,e,t] = meshToPet(model.Mesh);
% 生成轴对称的三角网格
[p,e,t] = pdegeom(model.Geometry,'Axisymmetric','on','Rotations',-1);
% 可以将生成的三角网格可视化
pdemesh(p,e,t);
在上面的示例代码中,使用了PDE Toolbox中的createpde函数创建了一个几何模型,该模型包含了一个圆和一个矩形,并保证了模型关于y轴对称。然后,使用pdegeom函数读取.pdeg文件,并通过设置“Axisymmetric”属性和“Rotations”属性来生成轴对称的三角网格。最后,使用pdemesh函数可视化生成的三角网格。
需要注意的是,在实际应用中,需要根据实际的几何模型和要求进行调整,并进行充分的测试和验证。
To generate a two-axis symmetric网格 in MATLAB, you can use the delaunay
function to create a 1/4-sized symmetric平面, and then use the 对称性
and 连接
options to create a resulting 3D symmetric网格. Here's an example:
% create a 1/4-sized symmetric平面
A = de la Ude ('对称性', '连接', '平面', '1/4');
This creates a 1/4-sized symmetric平面 that is created by using the 对称性
option and specifying the '连接'
option to create a new point in the平面 that is 1/4 size in x and y. The resulting 3D point cloud is then used to create a 3D symmetric grid by using the delaunay
function:
% create a 3D symmetric grid by using the de la Ude symmetric平面
grid = de la Ude ('平面', '1/4', '连接', '对称');
This creates a 3D symmetric grid that is created by using the 平面
option to create a 1/4-sized symmetric平面, and then using the 连接
option to create a new point in the平面 that is 1/4 size in x and y. The resulting 3D point cloud is then used to create a 3D symmetric grid by using the delaunay
function again:
% create a 3D symmetric grid by using the de la Ude symmetric平面
grid = de la Ude ('平面', '1/4', '连接', '对称', '网格');
In this example, the '网格'
option is used to specify that the resulting 3D point cloud should be used to create a 3D symmetric grid. This can be done by using the delaunay
function again to create a 3D symmetric point cloud, which is then used to create a 3D symmetric grid.
To complete the process, you can use the 对称性
option to specify the desired axis of symmetric analysis, and then use the 连接
option to specify the new point in the symmetric平面 that should be used to create the new 3D symmetric grid.
This process can be repeated for each axis of symmetric analysis to generate a two-axis symmetric grid.