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

 Accepted Answer

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 Comments

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
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:
  1. Define the original positions of the nodes.
  2. Calculate the displacement for each node based on the accumulated strain from the fixed point.
  3. 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.
Hi Yatharth
Yes this is what I was looking for.
Thanks for your input.
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.

Sign in to comment.

More Answers (0)

Products

Release

R2023b

Asked:

on 31 Jan 2024

Commented:

on 15 Feb 2024

Community Treasure Hunt

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

Start Hunting!