Gyroid Surface Area & Volume Calculation from existing code

조회 수: 22 (최근 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 CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by