Code covered by the BSD License  

Highlights from
Polygon_Intersection

4.875

4.9 | 8 ratings Rate this file 54 Downloads (last 30 days) File Size: 19.4 KB File ID: #18173
image thumbnail

Polygon_Intersection

by

 

01 Jan 2008 (Updated )

This function computes n-times intersection region of shapes collection

| Watch this File

File Information
Description

This function computes n-times intersection region of shapes collection and allows to identify every intersection region in which shapes intersect.

The function takes one argument as input, a structure S containing geometrical descriptions of shapes, and delivers one output argument, a structure containing the different shape intersections, with the shape indexes involded in the intersection and the associated area. The second argument is optional. Display_result is a binary value which indicates whether the result should be displayed (1) or not (0).

Input: S : Structure containing geometrical description of polygons.
        S(i) contains all information relative to the i-th shape
        S(i).P(j) gives access to the geometrical description of the j-th
        element of the i-th shape.
              XData : S(i).P(j).x : Vector
              YData : S(i).P(j).y : Vector
              Hole : S(i).P(j).hole : Binary value (1= hole, 0= fill).
              This binary variable indicates whether the consider polygon
              S(i).P(j) is a hole or not. Hole are represented with
              dotted lines on figures.

Output: Geo : Structure containing geometrical description of the
              intersection polygons, their area, and shape indexes used
              to compute the intersection.

              Geo(i).index contains the polygon indexes
              Geo(i).P contains the geometry of the polygon
                    P is a structure containing XData &
                    YData of polygons.
                    XData : Geo(i).P(j).x : Vector
                    YData : Geo(i).P(j).y : Vector
                    Hole : Geo(i).P(j).hole : Binary value (1
                    = hole, 0= fill)
              Geo(i).area contains the area of the i-th shape.

Acknowledgements

Polygon Clipper inspired this file.

MATLAB release MATLAB 7 (R14)
Other requirements The function uses Polygon Clipper, a function posted by Hölz. The MEX DLL of this function for Windows is included (Matlab 7 - Win 32). For other platforms, one needs to compile the source code, which can be found on Matlab Exchange (File Id: 8818)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
18 Jun 2014 David

That should have said total area minus the intersection. Not twice the intersection. My oops.

18 Jun 2014 David

Excellent work. Would have given it 5 stars if it was able to handle overlap of two polygons within the same group. (Currently it does not color their intersection on the plot and gives the total area of both instead of the total area minus twice the intersection) Does anyone know if there is an easy way to handle this situation? I'm looking at the code, but not too confident that I'll be able to successfully edit it myself.

18 Mar 2014 Marta Adamuszek  
22 Jan 2013 John Mahoney

Hi all,

I am interested in coloring the regions formed by a single self-intersecting polygon.

I was hoping that this would do it
%%
clear S
S(1).P.x = [0,5,5,2,2,4,4,1,1,3,3,0];
S(1).P.y = [0,0,5,5,2,2,1,1,3,3,4,4];
S(1).P.hole = 0;
Display_result = 1;
Accuracy = 1e-6;
Polygons_intersection(S,Display_result,Accuracy);
%%

However, using this function the region that is double-covered is not colored. Can the author (or anyone else) recommend an algorithm to accomplish a single coloring of all regions of N-covering?

Cheers, John

15 Aug 2012 jan  
13 Mar 2012 Romain W

I have to compute intersections between thousands of 2D triangles and "Polygons_intersection" takes an infinite amount of time to perform the task,I was wondering if there would be a way to improve greatly the computational time of the algorithm? Thanks a lot since I really need that function working at enhanced speed.

06 Mar 2012 Romain W

Hi everyone,

As mentioned by m4 Chrennikov, I've faced similar problems when using Polygon_intersection function.

It seems like in some cases, the function do not work properly, it returns structure with zeros areas (All P-s in each struct are empty []). Can you please let me know how to fix this problem?

Thank you very much
--------------------------------------------

I solved my problem by playing with the relative accuracy of the algorithm, thank you again for this fantastic function.

06 Mar 2012 Romain W

Hi everyone,

As mentioned by m4 Chrennikov, I've faced similar problems when using Polygon_intersection function.

It seems like in some cases, the function do not work properly, it returns structure with zeros areas (All P-s in each struct are empty []). Can you please let me know how to fix this problem?

Thank you very much

05 Apr 2011 m4 Chrennikov

Hi, all!
I've faced with problem when in some cases function do not work properly: it returns struct with zero areas. Any ideas on how can I solve this problem?

All P-s in each struct are empty [] except of the last P, which is 1x0 struct, may be this information is important.

14 Jun 2010 gjie Harith  
30 Jul 2009 Richard Branch  
06 Feb 2009 Ashok Prajapati  
Updates
19 Jun 2009

One bug corrected: degenerated polygons that created crashes are automatically deleted

Contact us