Area of Triangle

11 次查看(过去 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 中查找有关 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