Gyroid Surface Area & Volume Calculation from existing code
57 次查看(过去 30 天)
显示 更早的评论
The following code is to generate the shape of gyroid. From the code I want to calculate the surface area and volume. Instead of exporting the file and imprt in 3D design software could a potential solution, I want to get the surface area and volume from the code below:
clc
clear
close all
SizeL = 20;
Def = 40;
SFact = (SizeL/2)/pi;
A = SFact*pi;
D = A/Def;
[X,Y,Z] = meshgrid(-A:D:A);
OBJ = cos(X/SFact).*sin(Y/SFact) + cos(Y/SFact).*sin(Z/SFact) + cos(Z/SFact).*sin(X/SFact);
T = 0.5;
OBJ = (OBJ - T) .* (OBJ + T);
[F1,V1] = isosurface(X,Y,Z,OBJ,0);
[F2,V2] = isocaps(X,Y,Z,OBJ,0,'below');
F3 = [F1; F2+length(V1(:,1))];
V3 = [V1;V2];
p = patch('Vertices',V3,'Faces', F3, 'FaceColor', 'red', 'EdgeColor', 'none');
view(3);
camlight
Code Source: https://www.youtube.com/watch?v=uvCfVsFAcSw
0 个评论
采纳的回答
Abhinaya Kennedy
2023-11-28
Hi Syed,
As I understand, you would like to calculate the surface area and volume of a gyroid by adding to the code you have provided. Here is one possible way of obtaining it.
% Surface Area Calculation
SA = 0;
for i = 1:size(F3, 1)
v1 = V3(F3(i, 1), :);
v2 = V3(F3(i, 2), :);
v3 = V3(F3(i, 3), :);
edge1 = v2 - v1;
edge2 = v3 - v1;
area = 0.5 * norm(cross(edge1, edge2));
SA = SA + area;
end
% Volume Calculation
Volume = 0;
centroid = mean(V3, 1);
for i = 1:size(F3, 1)
v1 = V3(F3(i, 1), :);
v2 = V3(F3(i, 2), :);
v3 = V3(F3(i, 3), :);
Volume = Volume + abs(dot(v1 - centroid, cross(v2 - centroid, v3 - centroid))) / 6;
end
% Displaying the results
disp(['Surface Area: ', num2str(SA)]);
disp(['Volume: ', num2str(Volume)]);
This will output the required information.
Hope this helps!
1 个评论
jixiong fei
2024-3-31
can you please tell me what the following mean?
abs(dot(v1 - centroid, cross(v2 - centroid, v3 - centroid))) / 6;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!