Gyroid Surface Area & Volume Calculation from existing code

23 ビュー (過去 30 日間)
Syed Arafun Nabi
Syed Arafun Nabi 2023 年 11 月 12 日
コメント済み: jixiong fei 2024 年 3 月 31 日
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

採用された回答

AKennedy
AKennedy 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
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 ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by