Re: polygon intersection routine in IDL [message #52542] |
Tue, 13 February 2007 22:07  |
Weihua FANG
Messages: 26 Registered: January 2006
|
Junior Member |
|
|
Hi, dear mati,
I tested your function by 2 samples. One returned the overlap polygon
successfully. but the second one failed. is there anything wrong in my
code?
thank you in advance.
pro test_polygon_overlap
shape1 = fltarr(2,4)
shape2 = fltarr(2,4)
shape1[0,0] = 0.1
shape1[0,1] = 1.1
shape1[0,2] = 1.2
shape1[0,3] = 0.2
shape1[1,0] = 0.2
shape1[1,1] = 0.15
shape1[1,2] = 1.1
shape1[1,3] = 1.2
shape2[0,0] = 0.5
shape2[0,1] = 1.5
shape2[0,2] = 1.6
shape2[0,3] = 0.4
shape2[1,0] = 0.5
shape2[1,1] = 0.6
shape2[1,2] = 1.7
shape2[1,3] = 1.5
shape3 = shape_overlap (shape1, shape2, exists = exs)
print, exs
shape1 = fltarr(2,17)
shape1 [*,0] = [116.44991,41.441910]
shape1 [*,1] = [116.57357,41.374821]
shape1 [*,2] = [116.64723,41.312994]
shape1 [*,3] = [116.57488,41.002544]
shape1 [*,4] = [116.36967,40.928878]
shape1 [*,5] = [116.16840,40.984128]
shape1 [*,6] = [116.21576,41.053847]
shape1 [*,7] = [116.06185,41.099889]
shape1 [*,8] = [116.10263,41.168293]
shape1 [*,9] = [116.13683,41.214334]
shape1 [*,10] = [116.16577,41.264322]
shape1 [*,11] = [116.18156,41.319572]
shape1 [*,12] = [116.22891,41.344565]
shape1 [*,13] = [116.31442,41.357720]
shape1 [*,14] = [116.29337,41.387976]
shape1 [*,15] = [116.34468,41.422178]
shape1 [*,16] = [116.44991,41.441910]
shape2 = fltarr(2,6)
shape2 [*,0] = [116.21839,41.528731]
shape2 [*,1] = [116.61698,41.524784]
shape2 [*,2] = [116.72748,41.141984]
shape2 [*,3] = [116.30916,41.203810]
shape2 [*,4] = [116.13552,41.289316]
shape2 [*,5] = [116.21839,41.528731]
xrange = [116.06185 ,116.72748]
yrange = [40.928879 ,41.528732]
plot, shape1[0,*], shape1[1,*], xrange = xrange , yrange = yrange
oplot, shape2[0,*], shape2[1,*]
shape3= shape_overlap (shape1, shape2, exists = exs)
print, exs
end
On 2月14日, 下午12时00分, "Weihua FANG" <weihua.f...@gmail.com> wrote:
> Dear Mati,
>
> I appreciate your contribution and your prompt reply.
>
> I've downloaded your lib and gonna have a try ...
>
> Weihua
>
> On 2月14日, 上午11时47分, mme...@cars3.uchicago.edu wrote:
>
>
>
>> In article <1171422915.745198.302...@m58g2000cwm.googlegroups.com>, "Weihua FANG" <weihua.f...@gmail.com> writes:>hi, all,
>
>>> I need a routine to get the exact intersection, to be returned as a
>>> polygon, of 2 polygons (could be convex or concave) . I did some
>>> search and found similar routines from the libs of motley and Dr.
>>> D.Faning. but seems not the exact one i am looking for.
>
>>> Is there anybody knows such a routine in IDL?
>
>>> thanks a lot.
>
>> There is a routine like this in my library. You can find the library
>> on the users contribution page of RSI, under the name MIDL (or
>> MIDL_LIB). I'm not sure they put the newest library version up yet
>> but the routine exists in the older version as well. The routine's
>> name is SHAPE_OVERLAP.
>
>> Mati Meron | "When you argue with a fool,
>> m...@cars.uchicago.edu | chances are he is doing just the same"- 隐藏被引用文字 -
>
> - 显示引用的文字 -
|
|
|
Re: polygon intersection routine in IDL [message #52543 is a reply to message #52542] |
Tue, 13 February 2007 20:00   |
Weihua FANG
Messages: 26 Registered: January 2006
|
Junior Member |
|
|
Dear Mati,
I appreciate your contribution and your prompt reply.
I've downloaded your lib and gonna have a try ...
Weihua
On 2月14日, 上午11时47分, mme...@cars3.uchicago.edu wrote:
> In article <1171422915.745198.302...@m58g2000cwm.googlegroups.com>, "Weihua FANG" <weihua.f...@gmail.com> writes:>hi, all,
>
>> I need a routine to get the exact intersection, to be returned as a
>> polygon, of 2 polygons (could be convex or concave) . I did some
>> search and found similar routines from the libs of motley and Dr.
>> D.Faning. but seems not the exact one i am looking for.
>
>> Is there anybody knows such a routine in IDL?
>
>> thanks a lot.
>
> There is a routine like this in my library. You can find the library
> on the users contribution page of RSI, under the name MIDL (or
> MIDL_LIB). I'm not sure they put the newest library version up yet
> but the routine exists in the older version as well. The routine's
> name is SHAPE_OVERLAP.
>
> Mati Meron | "When you argue with a fool,
> m...@cars.uchicago.edu | chances are he is doing just the same"
|
|
|
|
Re: polygon intersection routine in IDL [message #52690 is a reply to message #52542] |
Wed, 14 February 2007 02:21  |
mmeron
Messages: 44 Registered: October 2003
|
Member |
|
|
In article <1171433274.480043.121140@q2g2000cwa.googlegroups.com>, "Weihua FANG" <weihua.fang@gmail.com> writes:
> Hi, dear mati,
>
> I tested your function by 2 samples. One returned the overlap polygon
> successfully. but the second one failed. is there anything wrong in my
> code?
>
> thank you in advance.
>
> pro test_polygon_overlap
>
>
> shape1 =3D fltarr(2,4)
> shape2 =3D fltarr(2,4)
> shape1[0,0] =3D 0.1
> shape1[0,1] =3D 1.1
> shape1[0,2] =3D 1.2
> shape1[0,3] =3D 0.2
> shape1[1,0] =3D 0.2
> shape1[1,1] =3D 0.15
> shape1[1,2] =3D 1.1
> shape1[1,3] =3D 1.2
>
> shape2[0,0] =3D 0.5
> shape2[0,1] =3D 1.5
> shape2[0,2] =3D 1.6
> shape2[0,3] =3D 0.4
> shape2[1,0] =3D 0.5
> shape2[1,1] =3D 0.6
> shape2[1,2] =3D 1.7
> shape2[1,3] =3D 1.5
>
> shape3 =3D shape_overlap (shape1, shape2, exists =3D exs)
>
> print, exs
>
>
> shape1 =3D fltarr(2,17)
> shape1 [*,0] =3D [116.44991,41.441910]
> shape1 [*,1] =3D [116.57357,41.374821]
> shape1 [*,2] =3D [116.64723,41.312994]
> shape1 [*,3] =3D [116.57488,41.002544]
> shape1 [*,4] =3D [116.36967,40.928878]
> shape1 [*,5] =3D [116.16840,40.984128]
> shape1 [*,6] =3D [116.21576,41.053847]
> shape1 [*,7] =3D [116.06185,41.099889]
> shape1 [*,8] =3D [116.10263,41.168293]
> shape1 [*,9] =3D [116.13683,41.214334]
> shape1 [*,10] =3D [116.16577,41.264322]
> shape1 [*,11] =3D [116.18156,41.319572]
> shape1 [*,12] =3D [116.22891,41.344565]
> shape1 [*,13] =3D [116.31442,41.357720]
> shape1 [*,14] =3D [116.29337,41.387976]
> shape1 [*,15] =3D [116.34468,41.422178]
> shape1 [*,16] =3D [116.44991,41.441910]
>
> shape2 =3D fltarr(2,6)
> shape2 [*,0] =3D [116.21839,41.528731]
> shape2 [*,1] =3D [116.61698,41.524784]
> shape2 [*,2] =3D [116.72748,41.141984]
> shape2 [*,3] =3D [116.30916,41.203810]
> shape2 [*,4] =3D [116.13552,41.289316]
> shape2 [*,5] =3D [116.21839,41.528731]
>
> xrange =3D [116.06185 ,116.72748]
> yrange =3D [40.928879 ,41.528732]
>
> plot, shape1[0,*], shape1[1,*], xrange =3D xrange , yrange =3D yrange
> oplot, shape2[0,*], shape2[1,*]
>
> shape3=3D shape_overlap (shape1, shape2, exists =3D exs)
>
> print, exs
>
>
> end
>
Well, thank you. I didn't use this routine for nearly a decade,
didn't notice that it has a bug. OK, go to line 72 of the routine,
the one which has a statement starting with
if Shape_area....
And replace it with
if Shape_area(sec) lt 0 then sec = reverse(sec,2)
Should work now, let me know if it doesn't
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
|
|
|