How to fill the area between two curves given as arrays of points

5 views (last 30 days)
I have an algorithm that produces a Bezier curve through deCastejau's algorithm, given a set of polygon points. I've also added an algorithm that calculates the offset curve at any given distance. This gives me two arrays of points, and I would like to color the area in between. Using the usual fill function, this works fine as long as the curve either doesn't self-intersect or the offset isn't too big, in which case the following happens:
Is there a way to fix this easily, or would I manually have to search where the areas overlap (which, given I don't have a direct formula for the offset curve, would not be that easy, though doable), to be able to color the area inside as well.
Here's the relevant code - bezier consists of points making up the red bezier curve, and offset consists of the points that create the offset curve.
X = [bezier(1,:), fliplr(offset(1,:))];
Y = [bezier(2,:), fliplr(offset(2,:))];
fill(X,Y,'b');
I have thought of doing this by simply connecting all pairs of points (as every point on the bezier curve has it's pair on the offset curve), and while that works, it also makes the interactive window rather unresponsive due to the sheer amount of lines.
I haven't posted the code to the Bezier curve and the offset, as really, this question would remain the same for any two curves given as sets of points, but I'm happy to provide it if it helps.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!