Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Finding the area inside a convex hull 3

Posted by Doug Hull,

This quick video answers a question about finding the area of the smallest polygon that covers a set of points. It is a chance to use a few commands in MATLAB to simplify a script. Here is the code that will be discussed.
 x1 = rand(1,10);
 y1 = rand(1,10);

 vi = convhull(x1,y1);
 polyarea(x1(vi),y1(vi))

 plot(x1,y1,'.')
 axis equal
 hold on
 fill ( x1(vi), y1(vi), 'r','facealpha', 0.5 ); 
 hold off

3 CommentsOldest to Newest

Ali replied on : 1 of 3
Hello Doug , Thank you for this video and this code. I have a question though. What can I do in order to find the integral of a function over a general polygon? In other words, in the case of area, we know that the function we are integrating is 1, but what if I am given a general function f(x,y) that I need to find its integral over a convex polygon? Note that I am given the polygon as a set of points similar to your example. Thanks in advance.
Doug replied on : 2 of 3
@Ali, I think you will find this most instructive: https://www.mathworks.com/help/matlab/ref/integral2.html Look at doing the triangular bit.

Add A Comment

Your email address will not be published. Required fields are marked *

Preview: hide