Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Tricontf

5.0
5.0 | 7 ratings Rate this file 19 Downloads (last 30 days) File Size: 9.39 KB File ID: #40847 Version: 1.1
image thumbnail

Tricontf

by

 

18 Mar 2013 (Updated )

Contouring and filled contouring for unstructured 2D triangular meshes

| Watch this File

File Information
Description

TRICONT and TRICONTF have functionality equivalent to that of CONTOUR and CONTOURF, but the surface is defined over a 2D mesh of triangular elements (which may have a non-convex hull and/or may contain interior holes).
TRIDEMO gives a demonstration.

Acknowledgements

This file inspired Two Phase Obstacle Problem In 2 D And Its Aposteriori Error Estimate.

MATLAB release MATLAB 7.7 (R2008b)
MATLAB Search Path
/
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
31 May 2016 Rich Pawlowicz

re: clabel - unfortunately, clabel calls will no longer work in matlab2014b and later. This is because you can no longer 'trick' clabel by faking up the kind of output that a call to 'contour' returns.

Comment only
09 May 2016 Nasser M. Abbasi  
08 Oct 2015 Silvio

Silvio (view profile)

Very nice code, I have just a problem. when I want to put a label on tricontf I got this problem:
Error using clabel (line 70)
Not enough contour handles.

The code I am running is this:
[C1,h2]=tricontf(x,y,tri,df,scala) ;
clabel(C1,h2);
where scala is a vector for the levels.
The contour plot appears smoothly, just clabel is not working. I am running matlab 2014b on a mac
Thanks,
Silvio

21 Apr 2015 Rich Pawlowicz

If it is an unstructured mesh than the hole is implicitly defined by a lack of triangles in it. So, short answer - yes, that's feasible.

Comment only
21 Apr 2015 mortain

Hello Rich,
thanks for the submission. I have an unstructured mesh with some holes in the middle and I don't have a mathematical formulation which defines their position. Would that be something feasible with your code?
Cheers

Comment only
06 Apr 2015 Ryan

Ryan (view profile)

 
03 Apr 2015 Rich Pawlowicz

Fixed - required changing > to >= in a couple of places (darned special cases)

Comment only
03 Apr 2015 Ryan

Ryan (view profile)

To amend the comment below, I see now that the first error occurs if any level is specified as max(Z) (e.g. substitute the line below).
v = sort([-10:10 min(Z(:)) max(Z(:))]);

Comment only
03 Apr 2015 Ryan

Ryan (view profile)

These are great functions, thanks for the submission!

Sometimes, I encounter problems with tricontf. It seems that if the levels vector is specified so that the last level is exactly max(Z), tricontf gives an error at line 194. However, I do not get errors from tricont, contour, or contourf. For example:

[X,Y,Z] = peaks(100);
DT = delaunayTriangulation(X(:),Y(:));
M = DT.ConnectivityList;
v = linspace(min(Z(:)),max(Z(:)),21);
figure
subplot(221); contour(X,Y,Z,v); title('contour')
subplot(222); tricont(X(:),Y(:),M,Z(:),v); title('tricont')
subplot(223); contourf(X,Y,Z,v); title('contourf')
subplot(224); tricontf(X(:),Y(:),M,Z(:),v); title('tricontf')
axis(findall(gcf,'Type','axes'),'equal',[-3 3 -3 3])

If I perturb the max(Z) in the levels, I do not get an error (e.g. substitute the line below), but that is not an ideal fix.
v = linspace(min(Z(:)),max(Z(:))+1e-10,21);

Also, tricontf produces an error again at line 194 if Z is constant, whereas tricont produces an empty plot and both contour and contourf throw a warning and produce an empty plot.

An update to fix these issues would be greatly appreciated!

Comment only
27 Jan 2015 Xinwen Li

the work is wonderful!
for most of time I get smooth contour lines.While sometimes the there exist "saw-tooth" on the contour lines

02 Jun 2014 rmc256

rmc256 (view profile)

Works wonderfully, better than previous submissions (tricontour). The contours of my mesh were being split with tricontour (produced two contours, even though same level and connected), but tricont produces the correct contours. Saved me a lot of debug time.

24 Mar 2013 Victor

Victor (view profile)

Works well! Thanks!

18 Mar 2013 Thomas Benson

I've been waiting for someone out there to do triangular mesh filled contours for ages now (I did have a go a trying to code myself but found it very tricky to make it generic). Hats off to you Rich. I haven't tested thoroughly but tidiness of code and what it promises to do means I'll give it 5 anyway!

Updates
03 Apr 2015 1.1

Fixing reported issues required changing > to >= in a couple of places (darned special cases)

Contact us