Question

I have the following that draws a polygon:

nVal = 33;
x = 164.8 + rand(nVal,1).*(354.6-164.8);
y = 66.3 + rand(nVal,1).*(222.3-66.3);
k = convhull(x,y);
plot(x(k),y(k),'r-',x,y,'b+')

If I want to fill out the shape, I think we can use patch. But, it seems that I'm not using it correct, as I didn't get the whole shape filled.

I used the following:

 patch(x,y,'r')

Thanks.

Was it helpful?

Solution

Use fill:

fill(x(k),y(k),[.75 .75 .75]) %// light gray. Or change color as desired

If you want the original points to be seen, you have to plot them after fill:

fill(x(k),y(k),[.75 .75 .75])
hold on
plot(x(k),y(k),'r-',x,y,'b+')

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top