Thread Subject: POLY2CW ??? what happened to it?

Subject: POLY2CW ??? what happened to it?

From: Paul

Date: 12 Nov, 2007 04:54:15

Message: 1 of 6

I'm having trouble using
inpolygon

and I need poly2cw to sort it out.

Where is it?

Subject: POLY2CW ??? what happened to it?

From: Steven Lord

Date: 12 Nov, 2007 05:10:42

Message: 2 of 6


"Paul " <par@ceri.memphis.edu> wrote in message
news:fh8m9n$hcb$1@fred.mathworks.com...
> I'm having trouble using
> inpolygon
>
> and I need poly2cw to sort it out.
>
> Where is it?

POLY2CW is a function in Mapping Toolbox, but INPOLYGON doesn't call POLY2CW
(at least not in R2007b, and not in previous versions as far as I remember).
What version of MATLAB are you using, what trouble are you experiencing with
INPOLYGON, and why do think you need POLY2CW to sort it out?

--
Steve Lord
slord@mathworks.com


Subject: POLY2CW ??? what happened to it?

From: Paul

Date: 12 Nov, 2007 05:57:47

Message: 3 of 6

"Steven Lord" <slord@mathworks.com> wrote in message
<fh8n8i$s4v$1@fred.mathworks.com>...
>
> "Paul " <par@ceri.memphis.edu> wrote in message
> news:fh8m9n$hcb$1@fred.mathworks.com...
> > I'm having trouble using
> > inpolygon
> >
> > and I need poly2cw to sort it out.
> >
> > Where is it?
>
> POLY2CW is a function in Mapping Toolbox, but INPOLYGON
doesn't call POLY2CW
> (at least not in R2007b, and not in previous versions as
far as I remember).
> What version of MATLAB are you using, what trouble are you
experiencing with
> INPOLYGON, and why do think you need POLY2CW to sort it out?
>
> --
> Steve Lord
> slord@mathworks.com
>
>

clear
close('all')

x1 = [1/4 1/2];
y1 = [1/2 3/4];
x2 = [1/2 3/4];
y2 = [1/4 1/2];

xv = [x1,x2];
yv = [y1,y2];




x = rand(1000,1);
y = rand(1000,1);

plot(xv,yv,'ro')

hold on
plot(x,y,'g.')

use = inpolygon(x,y,xv,yv);
plot(x(use),y(use),'r.')

%%%%%%%%%%%%%%%%%%%%%

you can see that when I merge the two segments of vertices,
then the area I want to isolate is not correct. This is
basically what my problem is since I have two track of
particles and I want to isolate the region between them as
inside a polygon

Subject: POLY2CW ??? what happened to it?

From: Steve Eddins

Date: 12 Nov, 2007 14:02:50

Message: 4 of 6

Paul wrote:
> [snip]
>
> clear
> close('all')
>
> x1 = [1/4 1/2];
> y1 = [1/2 3/4];
> x2 = [1/2 3/4];
> y2 = [1/4 1/2];
>
> xv = [x1,x2];
> yv = [y1,y2];
>
>
>
>
> x = rand(1000,1);
> y = rand(1000,1);
>
> plot(xv,yv,'ro')
>
> hold on
> plot(x,y,'g.')
>
> use = inpolygon(x,y,xv,yv);
> plot(x(use),y(use),'r.')
>
> %%%%%%%%%%%%%%%%%%%%%
>
> you can see that when I merge the two segments of vertices,
> then the area I want to isolate is not correct.
 > [snip]

It is correct. If you plot the polygon with lines between the vertices,
like this:

plot(xv,yv,'r')

you'll see that your polygon is self-intersecting in a kind of hourglass
shape. That explains your result.

--
Steve Eddins
http://blogs.mathworks.com/steve

Subject: POLY2CW ??? what happened to it?

From: Paul

Date: 12 Nov, 2007 23:53:24

Message: 5 of 6

Steve Eddins <Steve.Eddins@mathworks.com> wrote in message
<fh9mea$p6r$1@fred.mathworks.com>...
> Paul wrote:
> > [snip]
> >
> > clear
> > close('all')
> >
> > x1 = [1/4 1/2];
> > y1 = [1/2 3/4];
> > x2 = [1/2 3/4];
> > y2 = [1/4 1/2];
> >
> > xv = [x1,x2];
> > yv = [y1,y2];
> >
> >
> >
> >
> > x = rand(1000,1);
> > y = rand(1000,1);
> >
> > plot(xv,yv,'ro')
> >
> > hold on
> > plot(x,y,'g.')
> >
> > use = inpolygon(x,y,xv,yv);
> > plot(x(use),y(use),'r.')
> >
> > %%%%%%%%%%%%%%%%%%%%%
> >
> > you can see that when I merge the two segments of vertices,
> > then the area I want to isolate is not correct.
> > [snip]
>
> It is correct. If you plot the polygon with lines between
the vertices,
> like this:
>
> plot(xv,yv,'r')
>
> you'll see that your polygon is self-intersecting in a
kind of hourglass
> shape. That explains your result.
>
> --
> Steve Eddins
> http://blogs.mathworks.com/steve

This is EXACTLY why I was asking about POLY2CW routine. I
have to make the vertices of the polygon ordered clockwise.

Subject: POLY2CW ??? what happened to it?

From: Steve Eddins

Date: 13 Nov, 2007 15:09:24

Message: 6 of 6

Paul wrote:

>> It is correct. If you plot the polygon with lines between
> the vertices,
>> like this:
>>
>> plot(xv,yv,'r')
>>
>> you'll see that your polygon is self-intersecting in a
> kind of hourglass
>> shape. That explains your result.
>>
>> --
>> Steve Eddins
>> http://blogs.mathworks.com/steve
>
> This is EXACTLY why I was asking about POLY2CW routine. I
> have to make the vertices of the polygon ordered clockwise.
>

I'm not sure that POLY2CW, which is in the Mapping Toolbox as Steve Lord
said earlier, will help you. POLY2CW does not reorder the vertices of a
self-intersecting polygon to make it non self-intersecting.

--
Steve Eddins
http://blogs.mathworks.com/steve

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com