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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Using contours and inpolygon, an issue of unclosed contours

Asked by Dan on 24 Apr 2013

Hello, I have an issue I've been working on for days. I am using ocean bathymetries, and I've created contours of depth. I have used:

[C,h] = contourfm(lat,lon,depth)

This works, and looks great, and I understand the structure of C.

The next task is to see if a series of points which have depth data are inside or above these contours, the implication being that these points are within the ocean, and not below the bottom of the ocean. I have used a series of loops, but basically:

patchstart = find(C(1,:)==pointdepth);

xv= C(1,patchstart+1:patchstart+C(2,patchstart));

yv= C(1,patchstart+1:patchstart+C(2,patchstart));

IN = inpolygon(pointx,pointy,xv,yv);

There may be some errors above, as I've simplified it.

Basically, this works just fine. The problem is that the shapes in C aren't necessarilly 'closed'. The contours (bathymetry lines) are sometimes drawn in curvy fashion from one side of the plot to the other. Thus, when INPOLYGON checks the polygon, it CLOSES that polygon in a straight line from where the shape hits each edge of the axis. Because these lines are curvy and complex, the result is a crazy polygon that is not even close to accurate (that straight line suggests that some areas that are OUTSIDE of the contour are in, and some areas that are INSIDE end up being out - think of drawing a sin-wave, then drawing a line down the middle, and shading just the 'closed' areas).

So the issue is this: Is there a way to close a polygon by wrapping around the current set of axes? I'm not even sure that would solve my problem in all cases, but it might get me closer.

The CONTOURFM function draws the contours PERFECTLY, but the shapes in C are INCORRECT when redrawn with PATCH, etc.

Thanks for the help! (first time post!)

2 Comments

Sean de Wolski on 24 Apr 2013

Could you show a picture?

Jing on 27 Apr 2013

Do you mean you need to close the polygon by a customized line?

Dan

Products

No products are associated with this question.

0 Answers

Contact us