Area of Triangle

조회 수: 28 (최근 30일)
developer
developer 2011년 9월 1일
Hello, Is there any function to find the area of any triangle using 3D points in cartesian system, where i have the vertices of the triangle in 3d coordinate?
Thanks

채택된 답변

Grzegorz Knor
Grzegorz Knor 2011년 9월 1일
According to Wikipedia:
x = rand(3,1);
y = rand(3,1);
z = rand(3,1);
fill3(x,y,z,'r')
x = x(:)';
y = y(:)';
z = z(:)';
ons = [1 1 1];
A = 0.5*sqrt(det([x;y;ons])^2 + det([y;z;ons])^2 + det([z;x;ons])^2)
Grzegorz

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 9월 1일
Yes, use Heron's numerically stable algorithm. Here's a function I wrote to do it with the output of the isosurface function:
function [A]= areaIsosurface(F,V)
%Function to calculate the area of an isosurface generated by MATLAB's
% built-in isosurface().
%SCd 07/12/2010
%
%This function uses Heron's numerically stable formula available here:
%>>web('http://en.wikipedia.org/wiki/Heron''s_formula','-new');
%
%Input Arguments:
% [F,V] = isosurface(...);
% F: calculation above
% V: calculation above
%
%Output Arguments:
% A: surface area of the triangulated isosurface.
%
%Calculate side lengths:
sides = zeros(size(F,1),3); %Preallocate
sides(:,1) = sqrt(... %a
(V(F(:,1),1)-V(F(:,2),1)).^2+...
(V(F(:,1),2)-V(F(:,2),2)).^2+...
(V(F(:,1),3)-V(F(:,2),3)).^2);
sides(:,2) = sqrt(... %b
(V(F(:,2),1)-V(F(:,3),1)).^2+...
(V(F(:,2),2)-V(F(:,3),2)).^2+...
(V(F(:,2),3)-V(F(:,3),3)).^2);
sides(:,3) = sqrt(... %c
(V(F(:,1),1)-V(F(:,3),1)).^2+...
(V(F(:,1),2)-V(F(:,3),2)).^2+...
(V(F(:,1),3)-V(F(:,3),3)).^2);
%Sort so: sides(:,1)>=sides(:,2)>=sides(:,3).
sides = sort(sides,2,'descend');
%Calculate Area!
A = sum(sqrt(...
(sides(:,1)+(sides(:,2)+sides(:,3))).*...
(sides(:,3)-(sides(:,1)-sides(:,2))).*...
(sides(:,3)+(sides(:,1)-sides(:,2))).*...
(sides(:,1)+(sides(:,2)-sides(:,3)))))/4;
end

카테고리

Help CenterFile Exchange에서 Scalar Volume Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by