MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Jon
on 5 Feb 2013

I am developing a meandering river model. At each time step, centerline nodes are adjusted by a dx and dy value and the river moves about its floodplain. At some point, the bend of a river runs into another bend of the same river, causing a cutoff. In reality, the cutoff will occur when the *banks* intersect, not the centerline.

My problem is that my bank calculation method fails for segments with very high curvature (e.g. those that have just undergone a cutoff), but works sufficiently well elsewhere. I cannot figure out how else to generate my right and left banks to avoid this problem.

http://imgur.com/a/uHvRM for some images of the problem.

Here's what I'm doing:

Given a vector of X,Y centerline coordinates, I first calculate the downstream angle between the river centerline and the (arbitrary) valley centerline:

atan((Y2-Y1))/(X2-X1)). Actual code is

Xang = Xs(1:end-1); Xang_plus1 = Xs(2:end); Yang = Ys(1:end-1); Yang_plus1 = Ys(2:end); angles = atan2(Yang_plus1-Yang,Xang_plus1-Xang);

Once I compute these angles, I calculate the left and right banks using the following code:

Xl = Xs(1:end-1)-sin(pi-angles)*B; Yl = Ys(1:end-1)-cos(pi-angles)*B; Xr = Xs(1:end-1)+sin(pi-angles)*B; Yr = Ys(1:end-1)+cos(pi-angles)*B;

Like I said before, this code works very well except where the curvature is high, ie where the river changes directions drastically.

I've tried different thresholding, smoothing, and regridding techniques but can't find a robust method. I've looked at bufferm, but not only did it not work correctly (user error, I'm sure), it took ~10 seconds. This is a routine I need to run at least twice per time step over 1000s of time steps, so a 10s subroutine is unacceptable.

Does anyone have any suggestions for how I can generate my riverbanks accurately and quickly, or do I have to resort to curvature-based thresholding?

Thanks for any help!

*No products are associated with this question.*

Answer by Cedric Wannaz
on 5 Feb 2013

Edited by Cedric Wannaz
on 5 Feb 2013

Accepted answer

Your approach generates narrower streams than what you want, and will fail each time the angle is greater than pi/2, as at least one point delineating your buffer will essentially switch side(s).

`bufferm()` was known to have flaws but most of them were corrected. You could have a look at `bufferm2` though. I've never used them to be honest (I am using the ArcGIS geoprocessor and more recently arcpy to do these things), but if I had to place a wild guess at what might not work, I would bet on the fact that your segments are not polygons, but lines. Some packages for building buffers are able to deal with points/lines, but some aren't (they need, among other things, to be able to define polygons interior(s) and an exterior(s)).

Otherwise, what you want is (I guess) the intersect between parallels to each segment of your center line. You could get them easily by solving linear systems (intersecting lines) with only one particular case to manage: co-linearity between consecutive segments of the center line (note that there are two sub-cases [aligned and superimposed] that cannot be managed the same way). You might also want to truncate boundaries (the exterior ones) for angles greater than pi/2.

Show 6 older comments

Jon
on 5 Feb 2013

The problem is that it's possible and not entirely improbable to have two cutoffs at different sections of the river occur on the same timestep. I can work around this, though, but the problem I mentioned still remains: at the time step following a cutoff, when the banks are recomputed near the cutoff, they still erroneously intersect themselves. So the code thinks there's a cutoff when there's actually not a cutoff, and I have no robust way of informing the code that it's not a real cutoff...although typing this has given me an idea.

I would rather just compute the banks properly, because not only would it solve my problem of erroneous cutoffs, it would also make the results look more realistic for presentation purposes.

Also, I just tried the intersecting parallel lines method and the problem still remains at the regions of high curvature (cutoff nodes). You can hand draw a sharp bend on some paper and see why.

edit: added a screenshot of the failed method here: http://imgur.com/a/3VvYg

Cedric Wannaz
on 6 Feb 2013

The issue that even parallels won't solve is that your B is much greater than the length of segments from the center line. I have no easy solution for that (but I am still thinking about it). I tested `bufferm`; it works well but it is true that it is quite slow.

## 2 Comments

## Image Analyst

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/62224#comment_127157

Some screenshots would help illustrate your situation.

## Jon

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/62224#comment_127320

Thanks for the advice; I uploaded a few screenshots here: http://imgur.com/a/uHvRM