Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
volume of each tetrahedral

Subject: volume of each tetrahedral

From: Dave Brackett

Date: 29 Feb, 2012 18:19:12

Message: 1 of 6

Hi, is there an easy and fast way to calculate the volume of each individual tetrahedral from a 3D DelaunayTri mesh? T= DelaunayTri(x,y,z)

Thanks in advance.

Subject: volume of each tetrahedral

From: Roger Stafford

Date: 29 Feb, 2012 19:10:26

Message: 2 of 6

"Dave Brackett" wrote in message <jilq70$57u$1@newscl01ah.mathworks.com>...
> Hi, is there an easy and fast way to calculate the volume of each individual tetrahedral from a 3D DelaunayTri mesh? T= DelaunayTri(x,y,z)
>
> Thanks in advance.
- - - - - - - -
  If P1, P2, P3, and P4 are each the three cartesian coordinates of one of a tetrahedron's four vertices, then its volume is:

 V = 1/6*abs(dot(P2-P1,cross(P3-P1,P4-P1)));

Roger Stafford

Subject: volume of each tetrahedral

From: Dave Brackett

Date: 29 Feb, 2012 22:51:12

Message: 3 of 6

"Roger Stafford" wrote in message <jilt72$ft7$1@newscl01ah.mathworks.com>...
> "Dave Brackett" wrote in message <jilq70$57u$1@newscl01ah.mathworks.com>...
> > Hi, is there an easy and fast way to calculate the volume of each individual tetrahedral from a 3D DelaunayTri mesh? T= DelaunayTri(x,y,z)
> >
> > Thanks in advance.
> - - - - - - - -
> If P1, P2, P3, and P4 are each the three cartesian coordinates of one of a tetrahedron's four vertices, then its volume is:
>
> V = 1/6*abs(dot(P2-P1,cross(P3-P1,P4-P1)));
>
> Roger Stafford

Thanks for that. I have implemented it in a loop as follows:

T= DelaunayTri(x,y,z);
coords=[x,y,z];
V=zeros(size(T,1),1);
for i=1:size(T,1)
    i
V(i) = 1/6*abs(dot(coords(T(i,2),:)-coords(T(i,1),:),cross(coords(T(i,3),:)-coords(T(i,1),:),coords(T(i,4),:)-coords(T(i,1),:))));
end

This is quite slow for a large number of elements. I have tried vectorising it using:

V = 1/6*abs(dot(coords(T(:,2),:)-coords(T(:,1),:),cross(coords(T(:,3),:)-coords(T(:,1),:),coords(T(:,4),:)-coords(T(:,1),:))));

but this does give correct results. How can I vectorise it?
Thanks.

Subject: volume of each tetrahedral

From: Roger Stafford

Date: 1 Mar, 2012 00:57:31

Message: 4 of 6

"Dave B" wrote in message <jima50$jf$1@newscl01ah.mathworks.com>...
> ..... I have tried vectorising it using:
>
> V = 1/6*abs(dot(coords(T(:,2),:)-coords(T(:,1),:),cross(coords(T(:,3),:)-coords(T(:,1),:),coords(T(:,4),:)-coords(T(:,1),:))));
>
> but this does give correct results. How can I vectorise it?
- - - - - - - - -
  You definitely need to specify the particular dimension along which the dot product is to be performed. It's better practice to do the same with 'cross' too.

 P21 = coords(T(:,2),:)-coords(T(:,1),:);
 P31 = coords(T(:,3),:)-coords(T(:,1),:);
 P41 = coords(T(:,4),:)-coords(T(:,1),:);
 V = 1/6*abs(dot(P21,cross(P31,P41,2),2));

  You might also compare that time-wise to using a for-loop with the appropriate determinant which also gives you the volume:

 V=zeros(size(T,1),1);
 for i = 1:size(T,1)
  V(i) = 1/6*abs(det([P21(i,:);P31(i,:);P41(i,:)]));
 end

Roger Stafford

Subject: volume of each tetrahedral

From: Dave B

Date: 1 Mar, 2012 00:58:30

Message: 5 of 6

"Dave B" wrote in message <jima50$jf$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jilt72$ft7$1@newscl01ah.mathworks.com>...
> > "Dave Brackett" wrote in message <jilq70$57u$1@newscl01ah.mathworks.com>...
> > > Hi, is there an easy and fast way to calculate the volume of each individual tetrahedral from a 3D DelaunayTri mesh? T= DelaunayTri(x,y,z)
> > >
> > > Thanks in advance.
> > - - - - - - - -
> > If P1, P2, P3, and P4 are each the three cartesian coordinates of one of a tetrahedron's four vertices, then its volume is:
> >
> > V = 1/6*abs(dot(P2-P1,cross(P3-P1,P4-P1)));
> >
> > Roger Stafford
>
> Thanks for that. I have implemented it in a loop as follows:
>
> T= DelaunayTri(x,y,z);
> coords=[x,y,z];
> V=zeros(size(T,1),1);
> for i=1:size(T,1)
> i
> V(i) = 1/6*abs(dot(coords(T(i,2),:)-coords(T(i,1),:),cross(coords(T(i,3),:)-coords(T(i,1),:),coords(T(i,4),:)-coords(T(i,1),:))));
> end
>
> This is quite slow for a large number of elements. I have tried vectorising it using:
>
> V = 1/6*abs(dot(coords(T(:,2),:)-coords(T(:,1),:),cross(coords(T(:,3),:)-coords(T(:,1),:),coords(T(:,4),:)-coords(T(:,1),:))));
>
> but this does give correct results. How can I vectorise it?
> Thanks.

I meant to write that it *doesn't* give correct results after my vectorising attempt.

Subject: volume of each tetrahedral

From: Dave B

Date: 1 Mar, 2012 10:00:25

Message: 6 of 6

"Roger Stafford" wrote in message <jimhhr$m1p$1@newscl01ah.mathworks.com>...
> "Dave B" wrote in message <jima50$jf$1@newscl01ah.mathworks.com>...
> > ..... I have tried vectorising it using:
> >
> > V = 1/6*abs(dot(coords(T(:,2),:)-coords(T(:,1),:),cross(coords(T(:,3),:)-coords(T(:,1),:),coords(T(:,4),:)-coords(T(:,1),:))));
> >
> > but this does give correct results. How can I vectorise it?
> - - - - - - - - -
> You definitely need to specify the particular dimension along which the dot product is to be performed. It's better practice to do the same with 'cross' too.
>
> P21 = coords(T(:,2),:)-coords(T(:,1),:);
> P31 = coords(T(:,3),:)-coords(T(:,1),:);
> P41 = coords(T(:,4),:)-coords(T(:,1),:);
> V = 1/6*abs(dot(P21,cross(P31,P41,2),2));
>
> You might also compare that time-wise to using a for-loop with the appropriate determinant which also gives you the volume:
>
> V=zeros(size(T,1),1);
> for i = 1:size(T,1)
> V(i) = 1/6*abs(det([P21(i,:);P31(i,:);P41(i,:)]));
> end
>
> Roger Stafford

thanks very much for that. that is so much faster! excellent!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us