Non uniform scaling of Mesh geometry
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
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
If you have a .stl file you can extract the nodes and elements of the geometry. You can read more about it here. https://www.mathworks.com/help/pde/ug/pde.pdemodel.generatemesh.html#:~:text=Nodes%3A%20%5B3x10045%20double%5D%0A%20%20%20%20%20%20%20%20%20%20Elements%3A%20%5B10x5689%20double%5D
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
2024 年 2 月 14 日
Hi Yatharth
Thank you very much for your reply, but does not quite solve my problem. So I know how much each hexahedral change in volume. This results in that I know the strain (or scale) for each note this stain only work on the line element between two points.
Now let us say the note in (0,0,0) is fixed then all the distances between the points get smaller so point (1,0,0) moves a little u1 = du1 = ((1,0,0) - (0,0,0)) * s1
But for point it will move what point (1,0,0) and what the strain gives as following: du2 = ((2,0,0) - (1,0,0)) * s2 -> u2 = du1+du2
So what I need is to go from a strain feild to a displacement feild.

Best regards,
Jon
Yatharth
2024 年 2 月 15 日
Hi Jon, I think you want to calculate the displacement field from a given strain field for a given mesh. If we consider a 1D analogy with a chain of elements along a single axis, and you have the strain for each element, you can indeed calculate the displacement at each node given that the strain is uniform within each element.
Here's how you can approach this:
- Define the original positions of the nodes.
- Calculate the displacement for each node based on the accumulated strain from the fixed point.
- Update the positions of the nodes by adding the displacement to the original positions.
Here is an updated code for the same.
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 for Node 7 (shared by first and second hexahedron)
len = length(nodes);
strains = 0.90 + (1.10 - 0.90) * rand(len);
for i = 2:length(nodes)
% Only apply the strain to nodes that are along the positive x-axis
if nodes(i,1) > nodes(i-1,1)
% Calculate the displacement based on the strain value
% corresponding to the element that the node belongs to
element_index = nodes(i,1); % Assuming each node's x-coordinate corresponds to the element index
displacement_x = (nodes(i,1) - nodes(i-1,1)) * (strains(element_index) - 1);
% Apply the displacement to the node
nodes(i,1) = nodes(i,1) + displacement_x;
% If there are other nodes that share the same x-coordinate (i.e., part of the same vertical face),
% apply the same displacement to them
shared_nodes = find(nodes(:,1) == nodes(i,1));
for j = 1:length(shared_nodes)
nodes(shared_nodes(j),1) = nodes(shared_nodes(j),1) + displacement_x;
end
end
end
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 is something similar to what you are looking for.
Jon Skov
2024 年 2 月 15 日
Hi Yatharth
Yes this is what I was looking for.
Thanks for your input.
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 件)
カテゴリ
ヘルプ センター および File Exchange で Environment についてさらに検索
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
