Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IAH public
DeProj
Commits
ba351464
Commit
ba351464
authored
Jun 30, 2020
by
Jean-Yves TINEVEZ
Browse files
AREA3D Computes the area of a 3D closed polygon.
parent
8449afa6
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/area3d.m
0 → 100644
View file @
ba351464
function
area
=
area3d
(
p
)
%AREA3D Computes the area of a 3D closed polygon.
% p must be a Nx3 matrix.
n_vertices
=
size
(
p
,
1
);
% Put all vertex coordinates with respect to center.
center
=
mean
(
p
);
center
=
repmat
(
center
,
[
n_vertices
,
1
]
);
p
=
p
-
center
;
% Build small triangles.
index
=
[
2
:
n_vertices
1
];
p1
=
p
;
p2
=
p
(
index
,
:
);
% Cross product.
cp
=
cross
(
p1
,
p2
);
% Norm of each vector.
vn
=
euclidean_norm
(
cp
);
% Positive area.
area_triangle
=
abs
(
vn
);
% Total positive area.
area
=
sum
(
area_triangle
)
/
2
;
function
n
=
euclidean_norm
(
v
)
n
=
sqrt
(
sum
(
v
.*
v
,
ndims
(
v
)
)
);
end
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment