What controls curvature in contour, contourm, contourfm,... ?

5 views (last 30 days)
Hi all! I've been digging through the documentation and google all day but I can't figure out what controls the curvature of contourlines in MATLAB. I am mostly using contourm (mapping toolbox). I have produced a plot
and now I'd like to know, why did MATLAB connect all the areas of darkest red (instead of giving me multiple blobs)? It seems to me that the reason might be a maximum allowed curvature?
Any ideas? Thanks!!
  2 Comments
Chad Greene
Chad Greene on 25 Mar 2016
What data did you give contourfm to create the plot above?
LMS
LMS on 29 Mar 2016
vectors x,y,z where x is latitude, y is longitude, and z is elevation of the black points.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 29 Mar 2016
I was hoping someone who had the mapping toolbox would answer this, so I could avoid stepping in. But the answer is clear enough, and nobody else has. :)
Contouring can be different, depending on the specific case. So the code for contour (which presumes a gridded array of point on which to build the contour) can differ from that of a tool like contourm, which apparently can handle an unstructured set of scattered points.
Given an unstructured set, the only viable approach for such automatic contouring is a simple one. (Yes, one could use more complex schemes, but they will tend to fail far more easily. So for AUTOMATIC, ROBUST contouring from scattered data, I'll argue there is only one simple approach that I would choose.) In fact, the approach for contouring scattered data is surely quite closely related to how one would contour a regular lattice, but for one crucial step.
So in order to explain it, I'll first need to explain how one does contouring on a regular lattice. (This is why I tried to avoid stepping in initially, since this post will be lengthy. And most of the time on a lengthy response like this, the OP will step in with a comment like "I know all that. But why...")
Given a regular lattice, so an n by m array of points, where the spacing along each axis may be uniform or not, such as can be used by contour, the code would typically employ a simple approach. In fact, that scheme is easily generalized into higher dimensions for iso-surface tools.
1. Break each rectangle in the lattice into a pair of triangles, using one arbitrarily chosen orientation for the diagonal. For simplicity, one would choose the same orientation for that dissection for all rectangles in the lattice, although that is not technically required. These dissections create a simple triangulation of the lattice, which is easy to build, although that triangulation is never explicitly constructed, using a call to tools like delaunay.
2. Test every triangle s created. If the contour crosses any edge of the triangle, then it MUST cross exactly two triangles edges. (Here, I'm going to ignore degenerate cases.)
3. Find those two points where the contour crosses those two indicated edges, using simple linear interpolation along the edges. Two points determine a line.
4. If we assume a linear interpolant across the triangle, then the contour would be a straight line in that local area, and we have just identified the two points where the contour crosses that triangle. So again, two points determine a line, so we have now generated ONE line segment of a contour line.
5. We can now repeat the above scheme for every triangle, testing to see if the contour crossed it, or we can employ a marching scheme, wherein we might follow the contour from triangle to triangle. Either method works, as long as one is careful in the code.
Ok, so that is a rough outline of how a general contouring scheme would work. I call it rough because I am not now looking at the specific code used in a tool like contour, but because I have written complete tools for this purpose myself. A contouring scheme that works on a regular lattice CAN (if the person writing the code wants to do so) get tricky in the dissection process for each square, deciding which orientation one might employ to dissect any small rectangle. That will resolve cases where the contour could be broken down into smaller pieces. Anyway, filling in all the details takes some work, because you need to worry about degeneracies, about all the things to make it robust. Since the basic MATAB contouring tools return a nicely structured set of contours, they probably employ some sort of marching triangles scheme, but that is not necessary, and is irrelevant to the case at hand.
A contouring scheme that works on scattered data, generating a plot like the one shown, will employ a similar scheme, but for one crucial step in the beginning. Here we start out using a Delaunay triangulation of the points in the (x,y) plane. Given that triangulation, is it trivial to fall into the general outline I describe above to generate contours.
To convince yourself of that fact, look at the coloring employed. See that it shows what are essentially large triangles in regions where the data is sparse. Also, see that the domain of the contour is a convex one, even though the data has holes in it along the edges. There are triangles that completely cover the convex hull of the data. A Delaunay triangulation was surely employed here.
Given that Delaunay triangulation, using linear interpolation across each triangle is surely employed, again, one can tell this simply from looking at the coloring, but also from understanding how such a code would be written.
However, you ask about curvature. There is NO question about local curvature. That will not be employed or measured anywhere in the code. Just simple linear interpolants across each triangle in the tessellation. While one could get trickier, worrying about the shape of a contour line for a regular lattice of points, that will NOT be done for a scattered set of points.
  11 Comments
Chad Greene
Chad Greene on 6 Apr 2016
Edited: Chad Greene on 6 Apr 2016
Instead of projfwd and projinv, you may also consider these.

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!