Intersection of polyshape objects - MATLAB intersect - MathWorks France (2024)

Intersection of polyshape objects

collapse all in page

Syntax

polyout = intersect(poly1,poly2)

polyout = intersect(polyvec)

[polyout,shapeID,vertexID] = intersect(poly1,poly2)

[polyout,shapeID,vertexID] = intersect(polyvec)

[in,out] = intersect(poly1,lineseg)

___ = intersect(___,Name=Value)

Description

example

polyout = intersect(poly1,poly2) returns a polyshape object whose regions are the geometric intersection of two polyshape objects. The intersection contains the regions of poly1 and poly2 that overlap. poly1 and poly2 must have compatible array sizes.

example

polyout = intersect(polyvec) returns a polyshape object whose regions are the intersection of all the polyshape objects in the vector polyvec. The intersection contains the regions where all the polyshape objects in polyvec overlap.

example

[polyout,shapeID,vertexID] = intersect(poly1,poly2) also returns vertex mapping information from the vertices in polyout to the vertices in poly1 and poly2. The intersect function only supports this syntax when poly1 and poly2 are scalar polyshape objects.

The shapeID elements identify whether the corresponding vertex in polyout originated in poly1, poly2, or was created from the intersection. vertexID maps the vertices of polyout to the vertices of poly1, poly2, or the intersection.

[polyout,shapeID,vertexID] = intersect(polyvec) returns vertex mapping information from polyout to each element of the vector of polyshape objects polyvec.

example

[in,out] = intersect(poly1,lineseg) returns the line segments of lineseg that are inside and outside of poly1. The matrix lineseg has two columns. The first column defines the x-coordinates of the line segments and the second column defines the corresponding y-coordinates.

intersect supports this syntax only when poly1 is a scalar polyshape and lineseg contains no self-intersections.

___ = intersect(___,Name=Value) specifies options using one or more name-value arguments in addition to any of the input argument combinations in previous syntaxes. You can use any of the output argument combinations in previous syntaxes. For example, polyout = intersect(poly1,poly2,Simplify=false) returns a polyshape object whose vertices have not been modified regardless of intersections or improper nesting.

Examples

collapse all

Intersection of Two Polygons

Open Live Script

Create and plot two polygons.

poly1 = polyshape([0 0 1 1],[1 0 0 1]);poly2 = polyshape([0.75 1.25 1.25 0.75],[0.25 0.25 0.75 0.75]);plot(poly1)hold onplot(poly2)

Intersection of polyshape objects - MATLAB intersect- MathWorks France (1)

figure

Compute and plot the intersection of poly1 and poly2.

polyout = intersect(poly1,poly2)
polyout = polyshape with properties: Vertices: [4x2 double] NumRegions: 1 NumHoles: 0
plot(polyout)xlim([-0.2 1.4]);ylim([-0.2 1.2]);

Vector of Polygons

Open Live Script

Create a vector containing two polygons.

polyarray1 = polyshape([0 0 1 1],[1 0 0 1]);polyarray2 = polyshape([0.75 1.25 1.25 0.75],[0.25 0.25 0.75 0.75]);polyvec = [polyarray1 polyarray2]
polyvec = 1x2 polyshape array with properties: Vertices NumRegions NumHoles
plot(polyvec(1))hold onplot(polyvec(2))

Intersection of polyshape objects - MATLAB intersect- MathWorks France (3)

figure

Compute the intersection of the elements of poly1.

polyout = intersect(polyvec)
polyout = polyshape with properties: Vertices: [4x2 double] NumRegions: 1 NumHoles: 0
plot(polyout)xlim([-0.2 1.4]);ylim([-0.2 1.2]);

Intersection of polyshape objects - MATLAB intersect- MathWorks France (4)

Vertex Mapping

Open Live Script

Create two polygons and compute their intersection. Display the vertex coordinates of the intersection and the corresponding vertex mapping information.

poly1 = polyshape([0 0 1 1],[1 0 0 1]);poly2 = polyshape([0.75 1.25 1.25 0.75],[0.25 0.25 0.75 0.75]);[polyout,shapeID,vertexID] = intersect(poly1,poly2);[polyout.Vertices shapeID vertexID]
ans = 4×4 0.7500 0.2500 2.0000 1.0000 0.7500 0.7500 2.0000 2.0000 1.0000 0.7500 0 0 1.0000 0.2500 0 0

The first two vertices of the intersection originated in poly2, since the corresponding values in shapeID are 2.These vertices are the first and second vertices in the property poly2.Vertices, respectively, since their corresponding values in vertexID are 1 and 2. The last two vertices of polyout were created from the intersection because the corresponding values in shapeID and vertexID are 0.

Intersection of Polygon and Line

Open Live Script

Create a rectangular polygon and a line segment.

poly1 = polyshape([0 0 1 1],[1 0 0 1]);lineseg = [0.5 0.5; 1.5 1.5];

Compute the intersection of the polygon with the line segment, and determine which sections of the line segment are inside or outside of the polygon.

[in,out] = intersect(poly1,lineseg);plot(poly1)hold onplot(in(:,1),in(:,2),'b',out(:,1),out(:,2),'r')legend('Polygon','Inside','Outside','Location','NorthWest')

Intersection of polyshape objects - MATLAB intersect- MathWorks France (5)

Input Arguments

collapse all

poly1First input polyshape
scalar | vector | matrix | multidimensional array

First input polyshape, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: polyshape

poly2Second input polyshape
scalar | vector | matrix | multidimensional array

Second input polyshape, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: polyshape

polyvecpolyshape vector
vector

polyshape vector.

Data Types: polyshape

linesegLine segment coordinates
two-column matrix

Line segment coordinates, specified as a two-column matrix. The first column defines the x-coordinates of the line segments and the second column defines the y-coordinates. lineseg must have at least two rows and contain no self-intersections.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: polyout = intersect(poly1,poly2,Simplify=false)

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: polyout = intersect(poly1,poly2,"Simplify",false)

KeepCollinearPointsKeep collinear points as vertices
true or 1 | false or 0

Keep collinear points as vertices, specified as one of these numeric or logical values:

  • 1 (true) — Keep all collinear points as vertices.

  • 0 (false) — Remove collinear points so that the output polyshape contains the fewest vertices necessary to define the boundaries.

If you do not specify the KeepCollinearPoints name-value argument, the function assigns its value according to the values used during creation of the input polyshape objects.

  • If each input polyshape kept collinear points as vertices during creation, then the function sets KeepCollinearPoints to true.

  • If each input polyshape removed collinear points during creation, then the function sets KeepCollinearPoints to false.

  • If the collinear points of the input polyshape objects were treated differently, then the function sets KeepCollinearPoints to false.

SimplifyModify polygon vertices to simplify output
true or 1 (default) | false or 0

Modify polygon vertices to simplify, specified as one of these numeric or logical values:

  • 1 (true) — Modify polygon vertices to produce a well-defined polygon when the output vertices produce intersections or improper nesting.

  • 0 (false) — Do not modify output vertices regardless of intersections or improper nesting. Computing with ill-defined polygons can lead to inaccurate or unexpected results.

Output Arguments

collapse all

polyout — Output polyshape
scalar | vector | matrix | multidimensional array

Output polyshape, returned as a scalar, vector, matrix, or multidimensional array.

  • If you input two polyshape arguments, then they must have compatible sizes. For example, if two input polyshape vectors have different lengths M and N, then they must have different orientations (one must be a row vector and one must be a column vector). polyout is then M-by-N or N-by-M depending on the orientation of each input vector. For more information on compatible array sizes, see Compatible Array Sizes for Basic Operations.

  • If you provide a single input argument polyvec, then polyout is a scalar polyshape object.

shapeID — Shape ID
column vector

Shape ID, returned as a column vector whose elements each represent the origin of a vertex in the intersection.

  • The length of shapeID is equal to the number of rows in the Vertices property of the output polyshape.

  • The elements of shapeID depend on the number of input arguments:

    • If you provide two input arguments poly1 and poly2, then they must be scalar polyshape objects. The value of an element in shapeID is 0 when the corresponding vertex of the output polyshape was created by the intersection. An element is 1 when the corresponding vertex originated from poly1, and 2 when it originated from poly2.

    • If you provide one input argument polyvec that is a vector of polyshape objects, then shapeID contains the element index of polyvec from which the corresponding output vertex originated. The value of an element is 0 when the corresponding vertex was created by the intersection.

Data Types: double

vertexID — Vertex ID
column vector

Vertex ID, returned as a column vector whose elements map the vertices in the output polyshape to the vertices in the polyshape of origin. The elements of vertexID contain the row numbers of the corresponding vertices in the Vertices property of the input polyshape. An element is 0 when the corresponding vertex of the output polyshape was created by the intersection.

The length of vertexID is equal to the number of rows in the Vertices property of the output polyshape. If you provide two input polyshape objects, then intersect only supports this output argument if they are scalar.

Data Types: double

in — Inside coordinates
two-column matrix

Inside line segment coordinates, returned as a two-column matrix. The first column of in contains the x-coordinates of the line segments inside the input polyshape, and the second column contains the corresponding y-coordinates.

Data Types: double

out — Outside coordinates
two-column matrix

Outside line segment coordinates, returned as a two-column matrix. The first column of out contains the x-coordinates of the line segments outside of the input polyshape, and the second column contains the corresponding y-coordinates.

Data Types: double

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2017b

expand all

See Also

polyshape | xor

Commande MATLAB

Vous avez cliqué sur un lien qui correspond à cette commande MATLAB:

 

Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.

Intersection of polyshape objects - MATLAB intersect- MathWorks France (6)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Intersection of polyshape objects - MATLAB intersect
- MathWorks France (2024)

FAQs

How do you intersect two Polyshapes in Matlab? ›

polyout = intersect( poly1 , poly2 ) returns a polyshape object whose regions are the geometric intersection of two polyshape objects. The intersection contains the regions of poly1 and poly2 that overlap. poly1 and poly2 must have compatible array sizes.

How to find the intersection of two vectors in Matlab? ›

Intersection of Two Vectors and Their Indices

Find the values common to both A and B , as well as the index vectors ia and ib , such that C = A(ia) and C = B(ib) .

How to find the point of intersection of two graphs in matlab? ›

I would do it like this:
  1. % define x Axis and evaluate functions.
  2. x_points = -5:0.1:5;
  3. function1 = -x+1;
  4. function2 = x+1;
  5. index_intersection = find(function1 == function2);
  6. x_value_intersection = x_points(index_intersection);
  7. y_value_intersection = function1(index_intersection);
  8. % plot functions and intersection point:

What is the area of intersection in Matlab? ›

area = rectint(A,B) returns the area of intersection of the rectangles specified by position vectors A and B . If A and B each specify one rectangle, the output area is a scalar.

What is the Polyxpoly command in MATLAB? ›

Description. [ xi , yi ] = polyxpoly( x1 , y1 , x2 , y2 ) returns the intersection points of two polylines in a planar, Cartesian system, with vertices defined by x1 , y1 , x2 and y2 .

What is the command for intersect in MATLAB? ›

c = intersect(A, B, 'rows') when A and B are matrices with the same number of columns returns the rows common to both A and B . [c, ia, ib] = intersect(a, b) also returns column index vectors ia and ib such that c = a(ia) and c = b(ib) (or c = a(ia,:) and c = b(ib,:) ).

How do you find the intersection of two elements? ›

A ∩ B = {x : x ∈ A and x ∈ B}

That means x is an element of A ∩ B, if and only if x is an element of both A and B. Thus, we can use the word “AND” to represent the intersection of sets. Sometimes, the above expression can also be referred to as the intersection of sets formula.

What is the intersection of two vector spaces? ›

1: Intersection is a Subspace. Let V be a vector space and suppose U and W are subspaces. Then the intersection U∩W is a subspace of V.

How do you find the intersection of two graphs? ›

The Intersection Between Two Graphs

You find the point where the graph of f and the graph of g intersects by solving the equation f ( x ) = g ( x ) . Insert x into f ( x ) = − x − 1 because it's the simpler expression of the two. You could also insert x into g ( x ) , but it would be more work.

How do you find the intersection of two? ›

To find the point of intersection algebraically, solve each equation for y, set the two expressions for y equal to each other, solve for x, and plug the value of x into either of the original equations to find the corresponding y-value. The values of x and y are the x- and y-values of the point of intersection.

What is the intersection formula? ›

The point of intersection formula is used to find the point of intersection of the two lines, that is the meeting point of two lines. These two lines can be represented by the equation a1x+b1y+c1=0 and a2x+b2y+c2=0, respectively. It is possible to find point of intersection of three or more lines.

How do you find intersection with Fzero in Matlab? ›

Using fzero() to find the intersection of 2 functions. Assume you have functions y1(x) and y2(x). Create a new function y3(x) = y1(x) - y2(x). The zero of y3(x) is the intersection of y1(x) and y2(x).

How do you find the intersection of a function? ›

To determine the points of intersection of two functions, you need to find the values of the independent variable (usually x) for which both functions have the same dependent variable value (usually y).

How to combine two matrices in MATLAB? ›

Concatenating Matrices

You can also use square brackets to append existing matrices. This way of creating a matrix is called concatenation. For example, concatenate two row vectors to make an even longer row vector. To arrange A and B as two rows of a matrix, use the semicolon.

How to combine two images in MATLAB? ›

C = imfuse( A , B ) creates a composite image from two images, A and B . If A and B are different sizes, imfuse pads the smaller dimensions with zeros so that both images are the same size before creating the composite. The output, C , is a numeric matrix containing a fused version of images A and B .

How to combine two models in MATLAB? ›

You can merge the changes between the two Simulink models by clicking the Merge Mode button in the toolstrip. This creates a third file, targetFile , which can contain the changes from either the left model ( sl_aircraft1) or right model ( sl_aircraft2 ).

How do you concatenate two plots in MATLAB? ›

However, you can use the hold on command to combine multiple plots in the same axes. For example, plot two lines and a scatter plot. Then reset the hold state to off. When the hold state is on, new plots do not clear existing plots or reset axes properties, such as the title or axis labels.

References

Top Articles
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 5961

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.