No BSD License  

Highlights from
Contours for triangular grids

5.0

5.0 | 11 ratings Rate this file 68 Downloads (last 30 days) File Size: 341.35 KB File ID: #10408
image thumbnail

Contours for triangular grids

by Darren Engwirda

 

17 Mar 2006 (Updated 15 May 2006)

Generate smooth contours for functions defined on unstructured triangular grids

| Watch this File

File Information
Description

Plots the contours of a function defined on an unstructured triangular grid directly, without the need to interpolate back onto a Cartesian array.

I have attempted to replicate much of the functionality of the regular "contour" function.

Type "help tricontour"

Type "contourdemo" for some examples

You may also find my mesh generator "mesh2d.m" in the physics and Chem section helpful.

UPDATE 11/05/2006
- Can now be used with clabel
- A bit faster

UPDATE 15/05/2006
- Much more accurate (now uses quadratic interpolation)

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (17)
20 Mar 2006 John D'Errico

Very nice. This is a function that should have been in Matlab itself since the day they provided trisurf and trimesh. It handled some troublesome cases I tried when I tried to break it. I'll give it a 5 rating because it deserves that rating. My only wish is that it was even more compatible with the contour functionality of matlab. For example, no handles are returned, in case you wish to set a line color or style. It might also be nice to provide a way to label the contours via clabel.

21 Mar 2006 M. Oswald

Very good contribution. I wish the author could extend the tricontour function to handle 3D triangle meshes as well.

21 Mar 2006 Kong Zuor

This is what I have been looking for since I start using Matlab. Great job well done! I wish to see this code in the next Matlab release. I find this code very useful to those who solve CFD problems with matlab. The author deserve my five star ranking. I would encourage the author to advance this code for 3D case. I am free at last!
Many thanks

29 Mar 2006 Babak Asghari  
05 May 2006 prabhakaran sundhararaju

it's very usefull for chemical, mechanical and civil. to analysis critical domain. i wish to develop 3D domain also

08 Aug 2006 Rabi Tahir

Works well... seems to be a bit slow, but I may be showing a bias (comparing with traditional fortran generated machine code)

13 Jan 2007 Friedemann Groh  
03 Feb 2009 Clemens Moser

Works very well, there is just a minor issue: the contours are not interpolated at the boundaries of the surface .

19 Apr 2009 Nik F  
01 Sep 2009 Jack Kohoutek  
28 Jul 2010 Xavy Kong

A=[0 0 .5;1 0 .6; 1 1 .7; 1 1 .7; 2 1 .6; 2 2 .5];
x=A(:,1); y=A(:,2); z=A(:,3);
P=[x(:),y(:)]; T=[1,2,3;4,5,6;7,8,9];
figure(1)
[c,h] = tricontour(P,T,z,3); % why not work ?
figure(2)
T = delaunayn(P);
[c,h] = tricontour(P,T,z,3); % % why not work ?
% This has to be improved?????????????

28 Jul 2010 John D'Errico

In the test case given by Xavy, note that there are a pair of points at (x,y) == (1,1). This will cause any such routine to fail that is based on triangulating the data.

With replicates in your data, remove them, averaging the z values at those replicated points.

Of course, even this will not help your example, since you then try to create a triangulation

> T=[1,2,3;4,5,6;7,8,9];

You only have SIX points in the set of point in A. Surely you cannot create a triangulation that refers to points 7, 8 and 9 too! A valid triangulation of this data would be

T = [1 2 3;2 3 5;3 5 6];

See that I never needed to use point 4, but also that this is a valid triangulation. I would expect tricontour to work properly with this triangulation.

29 Jul 2010 Xavy Kong

Sorry I missed three pnts when I shortened the lines. It should be like this.
A=[0 0 .5;1 0 .6; 1 1 .7;1 1 .7;2 1 .6;2 2 .5;1 1 .7;2 0 .4;2 1 .6];
x=A(:,1); y=A(:,2); z=A(:,3);
P=[x(:),y(:)]; T=[1,2,3;4,5,6;7,8,9];
I tried to use Fepoint format as in tecplot, but your suggestion not using pnt no.4 will plot the contour lines between my triangulars not within them. I am sorry that I did not quite understand the clauses arround 'bnd(next) = ce; % Found bnd edge' . Anyway, you have done a very nice job and I really appreciate your contribution and your assistance to me. I can try to fix my own problem later.

09 Aug 2010 Steve Fitzgerald

I'm sure this will be 5* when I get it to work; excuse my ignorance. I have a triangular mesh and x,y,z data that I plot with

trisurf(tri, x, y, z)

and I tried

[c, h] = tricontour([x y], tri, z, 15)

but I get an error where it tries flag(NaN). I'm pretty sure my data is OK, and trisurf works fine...

10 Jun 2011 illoul lounes

very usful, must be integrated to matlab.

thanks !

10 Jun 2011 Yan  
18 Jul 2011 Ben

Why I got some artifacts when using my own triangulated mesh? It generated some "contours" at the places where no triangles exist. Does anybody know why?

The mesh is no problem; I double checked.

Please login to add a comment or rating.
Updates
11 May 2006

clabel support

15 May 2006

quadratic interpolation

Tag Activity for this File
Tag Applied By Date/Time
specialized Darren Engwirda 22 Oct 2008 08:18:50
plotting Darren Engwirda 22 Oct 2008 08:18:50
unstructured Darren Engwirda 22 Oct 2008 08:18:50
mesh Darren Engwirda 22 Oct 2008 08:18:50
graphics Darren Engwirda 22 Oct 2008 08:18:50
contours Darren Engwirda 22 Oct 2008 08:18:50
please try this Xavy Kong 28 Jul 2010 04:49:16
why not work Xavy Kong 28 Jul 2010 04:49:16
contours Pascal 01 Aug 2011 08:18:41

Contact us at files@mathworks.com