File Exchange Pick of the Week

January 21st, 2008

Practical Example: Generating points inside a polygon

Notice the link at the bottom for a one minute survey that can get you into a drawing for a MATLAB t-shirt!

This ten minute video shows how to modify the help example for INPOLYGON to generate a set number of points inside of a random polygon. The coding process is shown from beginning to end, with incremental testing, debugging and commentary on my though process.

iconFiles.jpgiconFree.jpgiconPod.jpg

5 Responses to “Practical Example: Generating points inside a polygon”

  1. Ryan Gray replied on :

    It seems there’s a problem again with your M4V conversion. Quicktime and iTunes say it’s MPEG-4 video, but they don’t think it has a video track and only play audio.

  2. Doug replied on :

    Ryan,

    Seems there was a slight change in file output since I wrote my MATLAB scripts that automate FTPing the files up to the server. Problem solved now. Thanks!

    Doug

  3. siv replied on :

    we have a data that contains long,lat and data values we have to plot a grid image using that data values how to get a grid image

    and we have to mask the grid image to india polygon

  4. Doug replied on :

    @sivi,

    You might want the mapping toolbox, dependent on what you are doing.

    I think you should send the details of what you are doing to:

    http://www.mathworks.com/support

    Doug

  5. Nathan replied on :

    Unfortunately this code has no runtime guarantees – I would avoid this algorithm for large numbers of random points.

    A more robust solution would involve triangulating the polygon and then picking a random point in a random triangle. Runtime is guaranteed to be linear in the number of points.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.