フィルターのクリア

Non uniform scaling of Mesh geometry

4 ビュー (過去 30 日間)
Jon Skov
Jon Skov 2024 年 1 月 31 日
コメント済み: Yatharth 2024 年 2 月 15 日
Hi,
I am trying to scale the size of a mesh geometry with a scalar field.
So each node in the mesh is given a scalar, eg. 1.01, to expand the mesh around that node with 1% while the node right beside it might be given a scalar of 0.95 to contract the mesh around this node with 5 %. This will result in a change in size and shape, when performed on all nodes in the entire mesh geometry.
Is it possible to perform this operation with MATLAB ?
Best regards

採用された回答

Yatharth
Yatharth 2024 年 2 月 14 日
Hi Jon,
I realize you're looking to adjust the size of specific nodes within a mesh structure.
Altering any single node will impact the connected elements because these elements—like lines, triangles, quadrilaterals, and tetrahedra—are determined by their corner points, or nodes. Thus, resizing a node's location results in a corresponding transformation in both the dimensions and configuration of every element that includes that node.
In MATLAB, if you have a matrix of nodes and you modify the coordinates of one of those nodes, any operation that uses the modified node matrix to create or visualize the geometry will reflect the change.
You can modify the nodes by simple element by element matrix multiplication.
nodes = oldMesh.Nodes; %extracting nodes from the geometry
nodeLen = size(nodes,2) %determining the total number of nodes
scalars = 0.90 + (1.10 - 0.90) * rand(1, nodeLen); %defining a random Scalar matrix
new_nodes = nodes.*scalars; %element by element matrix multiplication to get a new node
Here's a simple MATLAB example illustrating this:
nodes = [
0, 0, 0; % Node 1
1, 0, 0; % Node 2
1, 1, 0; % Node 3
0, 1, 0; % Node 4
0, 0, 1; % Node 5
1, 0, 1; % Node 6
1, 1, 1; % Node 7
0, 1, 1; % Node 8
% Additional nodes for the second hexahedron
2, 0, 0; % Node 9
2, 1, 0; % Node 10
2, 0, 1; % Node 11
2, 1, 1; % Node 12
% Additional nodes for the third hexahedron
3, 0, 0; % Node 13
3, 1, 0; % Node 14
3, 0, 1; % Node 15
3, 1, 1; % Node 16
];
% Connectivity of the elements (faces of the hexahedrons)
% Each row defines a face with four node indices
elements = [
% First hexahedron
1, 2, 3, 4;
5, 6, 7, 8;
1, 2, 6, 5;
2, 3, 7, 6;
3, 4, 8, 7;
4, 1, 5, 8;
% Second hexahedron
2, 9, 10, 3;
6, 11, 12, 7;
2, 9, 11, 6;
9, 10, 12, 11;
10, 3, 7, 12;
% Third hexahedron
9, 13, 14, 10;
11, 15, 16, 12;
9, 13, 15, 11;
13, 14, 16, 15;
14, 10, 12, 16;
];
% Plot the original interconnected hexahedrons
figure;
patch('Vertices', nodes, 'Faces', elements, 'FaceColor', 'cyan', 'FaceAlpha', 0.3);
axis equal;
hold on;
xlabel('X');
ylabel('Y');
zlabel('Z');
view(3);
% Scale factor
s = 1.5;
% Scale (move) Node 7
nodes(7, :) = nodes(7, :) * s;
nodes(12, :) = nodes(12, :) * s; % Node 12 is also affected as it's the same physical point
nodes(11, :) = nodes(11, :) * s/2;
nodes(9, :) = nodes(9, :) * s/2;
% Plot the new interconnected hexahedrons after scaling Node 7
patch('Vertices', nodes, 'Faces', elements, 'FaceColor', 'none', 'EdgeColor', 'red', 'LineWidth', 2);
legend('Original', 'Scaled');
title('Effect of Scaling a Shared Node on Interconnected Hexahedral Elements');
hold off;
I hope this example provides clarity on the process of changing individual nodes.
  4 件のコメント
Jon Skov
Jon Skov 2024 年 2 月 15 日
Hi Yatharth
Yes this is what I was looking for.
Thanks for your input.
Yatharth
Yatharth 2024 年 2 月 15 日
Hi Jon, thank you for your affirmation for the correctness of the answer. It would be great if you could mark the answer as accepted. This would help in increasing the visibility of this answer in the community and helping others.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by