Area of Triangle

16 ビュー (過去 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 Center および File ExchangeScalar Volume Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by