File Exchange

## Polygon_Intersectio​n

version 1.1.0.0 (19.4 KB) by Guillaume JACQUENOT

### Guillaume JACQUENOT (view profile)

This function computes n-times intersection region of shapes collection

Updated 19 Jun 2009

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
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.

### Cite As

Guillaume JACQUENOT (2020). Polygon_Intersection (https://www.mathworks.com/matlabcentral/fileexchange/18173-polygon_intersection), MATLAB Central File Exchange. Retrieved .

Moritz Cremer

### Moritz Cremer (view profile)

Does not work: "Undefined function or variable 'PolygonClip'."

Allen Lee

Or Benaim

### Or Benaim (view profile)

Hi! like Sam Tong I am getting the problem "Undefined function 'PolygonClip'. Can anyone assist on how to install/compile it? Thanks

Joe Passman

Jaume Miro

Good, thanks!

Sam Tong

### Sam Tong (view profile)

I am getting the problem "Undefined function 'PolygonClip' for input arguments of type 'struct'" when i run it. Do I have to load the dll before I run? How do i do that without a header file?

IR_Image

Qingping

### Qingping (view profile)

Is there a X64 version?

Makrim

David

### David (view profile)

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

David

### David (view profile)

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.

John Mahoney

### John Mahoney (view profile)

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

jan

Romain W

### Romain W (view profile)

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.

Romain W

### Romain W (view profile)

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.

Romain W

### Romain W (view profile)

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

m4 Chrennikov

### m4 Chrennikov (view profile)

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.

gjie Harith

Richard Branch

Ashok Prajapati

### Ashok Prajapati (view profile)

 19 Jun 2009 1.1.0.0 One bug corrected: degenerated polygons that created crashes are automatically deleted
##### MATLAB Release Compatibility
Created with R14
Compatible with any release
##### Platform Compatibility
Windows macOS Linux