No BSD License  

Highlights from
Contours for triangular grids

5.0

5.0 | 17 ratings Rate this file 110 Downloads (last 30 days) File Size: 341 KB File ID: #10408
image thumbnail

Contours for triangular grids

by

 

17 Mar 2006 (Updated )

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)

Acknowledgements

This file inspired Trisurfc and Trigradient.M.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (24)
06 Jul 2014 Manuel Diaz  
04 Feb 2013 Michael

Great! any plans to make a version with filled contours? (like contourf) that'd be even better!

30 Jan 2013 Kim Nguyen

could somone please help, ive tried following the examples but it keeps telling me i dont put in enough arguments.
i have x,y, and dz as my coords

26 Sep 2012 Nachiket Patil  
21 Aug 2012 David

Thank you Darren. I appreciate your superb contribution.

09 May 2012 l l

GOOD

19 Feb 2012 lekshmi  
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.

10 Jun 2011 Yan  
10 Jun 2011 illoul lounes

very usful, must be integrated to matlab.

thanks !

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...

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.

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.

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?????????????

01 Sep 2009 Jack Kohoutek  
19 Apr 2009 Nik F  
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 .

13 Jan 2007 Friedemann Groh  
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)

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

29 Mar 2006 Babak Asghari  
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

21 Mar 2006 M. Oswald

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

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.

Updates
11 May 2006

clabel support

Contact us