Area of Triangle
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Grzegorz Knor
le 1 Sep 2011
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
0 commentaires
Plus de réponses (1)
Sean de Wolski
le 1 Sep 2011
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
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!