MATLAB code of intersection (2024)

Info

This question is locked. Reopen it to edit or answer.

100 views (last 30 days)

Show older comments

Liza L on 28 Mar 2024

  • Link

    Direct link to this question

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection

  • Link

    Direct link to this question

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection

Locked: Rena Berman on 5 Jun 2024 at 18:16

Hello, i intersect two sets of lines from two different origins at a distance of 10 cm from 0 to 90 degrees with an angle difference of two degrees. A straight line is obtained from the intersection of lines of the same degree. From the collision of lines, twice the degree of curvature is obtained. I need a MATLAB code to draw this straight line and curves.

MATLAB code of intersection (2)

1 Comment

Show -1 older commentsHide -1 older comments

Rena Berman on 5 Jun 2024 at 18:15

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#comment_3180121

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#comment_3180121

(Answers Dev) Restored edit

This question is locked.

Answers (3)

Matt J on 29 Mar 2024

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#answer_1433201

Edited: Matt J on 29 Mar 2024

Open in MATLAB Online

f=@(z) z(:,1:2)./z(:,3);

t=(0:2:30)'; e=ones(size(t));

D=[cosd(t), sind(t), 0*e];

L1=cross(e*[0 0 1], D); L2=cross(e*[5 0 1], D.*[-1 1 1]);

P=f(cross( L1(1:end-1,:) , L2(2:end,:) ));

plot(P(:,1), P(:,2), 'x-', 5-P(:,1),P(:,2),'x-'); xline(2.5);

MATLAB code of intersection (5)

0 Comments

Show -2 older commentsHide -2 older comments

William Rose on 28 Mar 2024

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#answer_1433156

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#answer_1433156

@Liza L, what have you tried so far?

The first part of your question, drawing the straight lines, shouldn't be too hard. Draw a line by specifying its endpoints. You can use a for loop to call plot() multiple times, with "hold on", so that successive plots will all be kept on the fiogure.

Then there is the plot of the curve. The curve is composed of the set of points where the lines intersect. If you have the endpoints of a line, you can get the y=mx+b equation for the line. Then use the formua for the intersection of two lines to get the cordinates of one point. Repeat for successive pairs of lines to find a list on intersecting points which make up the curve of interest. Then plot those points.

2 Comments

Show NoneHide None

William Rose on 29 Mar 2024

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#comment_3114181

Open in MATLAB Online

@Liza L

Here is a simple example of how you could draw the lines. Maybe you can come up with better way to do it.

deg=0:3:90;

x1end=10*cosd(deg); % line 1 x-endpoints

y1end=10*sind(deg); % line 1 y-endpoints

x2end=10-10*cosd(deg); % line 2 x-endpoints

y2end=y1end; % line 2 y-endpoints

figure;

for i=1:length(deg)

plot([0,x1end(i)],[0,y1end(i)],'-b'); hold on;

plot([10,x2end(i)],[0,y2end(i)],'-b')

end

axis equal

MATLAB code of intersection (8)

By the way, you said in your post that the origins should be 10 cm apart, but they are only 5 apart in your figure. I have made the origins 10 apart, above.

Now work on the intersections. It appears from the curves drawn in your plot that you are interested in the intersection of pairs of lines that differ by 0, 1, or -1 in their degree index. That was not obvious to me from the text of your intial posting.

William Rose on 29 Mar 2024

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#comment_3114761

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#comment_3114761

Open in MATLAB Online

@Liza L,

The symbolic solution for the intersections, by @John D'Errico at the site he links to, is very impressive. And the solution of @Matt J, using cross products, is also very elegant.

Another solution is below. Not as nice as their solutions, but it just shows there are multiple ways to do things.

A general solution for the intersection of two lines is to find x that is the same for both. Line 1 is y=m1x+b1, and line 2 is y=m2x+b2. They intersect at the point where m1x+b1=m2x+b2, i.e. the intersection is at

MATLAB code of intersection (10) .

For this particular problem, the lines that go through the origin have slope=m1=tan(deg1) and intercept b1=0, where deg1 is the line angle, in degrees. The lines that go through the point x=10,y=0 have slope m2=-tan(deg2) and intercept b2=10*tan(deg2). Plugging in the values for m1, b1, m2, b2 into the formula for x_int, and simplifying, we get

MATLAB code of intersection (11) .

Once we know x_int, we can find y_int:

MATLAB code of intersection (12)

Plugging in the values for m1 and b1, this becomes

MATLAB code of intersection (13)

Use the formulas for x_int and y_int, above, to write a script that plots the curves.

STarting with the script I offered above, and adding to it, we get

deg=3:3:90;

x1end=10*cosd(deg); % line 1 x-endpoints

y1end=10*sind(deg); % line 1 y-endpoints

x2end=10-10*cosd(deg); % line 2 x-endpoints

y2end=y1end; % line 2 y-endpoints

figure;

for i=1:length(deg)

plot([0,x1end(i)],[0,y1end(i)],'-b'); hold on;

plot([10,x2end(i)],[0,y2end(i)],'-b')

end

axis equal

% Find intersection points where line 1 is 3 deg higher than line 2

xint1=10*tand(deg(1:19))./(tand(deg(2:20))+tand(deg(1:19)));

yint1=tand(deg(2:20)).*xint1;

% Find intersection points where line 1 is 3 deg lower than line 2

xint2=10*tand(deg(2:20))./(tand(deg(1:19))+tand(deg(2:20)));

yint2=tand(deg(1:19)).*xint2;

% Find intersection points where line 1 and line 2 have same degrees

xint3=10*tand(deg(1:20))./(tand(deg(1:20))+tand(deg(1:20)));

yint3=tand(deg(1:20)).*xint3;

% Plot the intersection points

plot(xint1,yint1,'-r.',xint2,yint2,'-g.',xint3,yint3,'-k.')

MATLAB code of intersection (14)

John D'Errico on 29 Mar 2024

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#answer_1433186

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/2100311-matlab-code-of-intersection#answer_1433186

Edited: John D'Errico on 29 Mar 2024

I answered exactly this question only recently. So your class must be all getting this homework assignment.

https://www.mathworks.com/matlabcentral/answers/2092511-lines-that-meet-each-other?s_tid=srchtitle

In my answer, I derived the governing equation of the intersections of those lines. Of course, your question also tells me I did their homework assignment. Sigh. Every once in a while one gets past.

0 Comments

Show -2 older commentsHide -2 older comments

This question is locked.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsSurfaces, Volumes, and PolygonsSurface and Mesh Plots

Find more on Surface and Mesh Plots in Help Center and File Exchange

Tags

  • matlab
  • line
  • intersection

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


MATLAB code of intersection (16)

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

Contact your local office

MATLAB code of intersection (2024)

FAQs

MATLAB code of intersection? ›

C = intersect( A,B ) returns the data common to both A and B , with no repetitions.

What is the intersect tool in Matlab? ›

c = intersect( shape1,shape2 ) generates the shape obtained by intersecting shape1 and shape2 and returns a polygon object for resultant 2-D shape or a custom 3-D object for resultant 3-D shape. Alternatively, you can also use the '&' operator to intersect the shapes ( c = shape1 & shape2 ).

How do you find the intersection points of two lines in Matlab? ›

[ 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 intersection in code? ›

The intersection() method returns a set that contains the similarity between two or more sets. Meaning: The returned set contains only items that exist in both sets, or in all sets if the comparison is done with more than two sets. As a shortcut, you can use the & operator instead, see example below.

What is the intersection command in MATLAB? ›

Description. C = intersect( A,B ) returns the data common to both A and B , with no repetitions. C is in sorted order. If A and B are tables or timetables, then intersect returns the set of rows common to both tables.

What is the Intersect command? ›

Creates a 3D solid, surface, or 2D region from overlapping solids, surfaces, or regions.

What is the formula for point of intersection? ›

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 the intersection of two rectangles 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. A and B can also be matrices, where each row is a position vector.

What is the character code for intersection? ›

Unicode Character “∩” (U+2229)

How do you write an intersection? ›

The intersection of sets can be denoted using the symbol '∩'. As defined above, the intersection of two sets A and B is the set of all those elements which are common to both A and B. Symbolically, we can represent the intersection of A and B as A ∩ B.

What is the symbol for intersection? ›

definition and notation

The intersection operation is denoted by the symbol . The set A ∩ B—read “A intersection B” or “the intersection of A and B”—is defined as the set composed of all elements that belong to both A and B.

How do you find the intersection of two circles in Matlab? ›

[ xout , yout ] = circcirc( centerx1 , centery1 , radius1 , centerx2 , centery2 , radius2 ) finds the intersection of two circles with the specified centers and radii, in Cartesian coordinates.

How do you find the intersection of two functions? ›

Here's a step-by-step process:
  1. Write down the equations of the two functions, f(x) and g(x).
  2. Set the two functions equal to each other: f(x) = g(x).
  3. Solve the equation for x. ...
  4. For each x-value found in step 3, plug it back into either f(x) or g(x) to find the corresponding y-value.

How do you find the intersection of two sets? ›

For any two sets A and B, the intersection, A ∩ B (read as A intersection B) lists all the elements that are present in both sets (common elements of A and B). For example, if Set A = {1,2,3,4,5} and Set B = {3,4,6,8}, A ∩ B = {3,4}.

What is the use of intersect tool? ›

With the Intersect, tool you can create a curve at the intersection of a surface with other surfaces, or a surface with a datum plane. You can also create a curve at the intersection of two sketches, or sketched datum curves that become surfaces after they are extruded.

What is the intersect method? ›

The intersect method is a drilling method that uses two drills, each at the far end of the bore path. By means of the intersect method, drilling is done from two sides towards each other. One of the biggest advantages of the intersect method is that you can double the maximum achievable drill length.

What information did the intersect tool create? ›

The Intersect tool calculates the geometric intersection of any number of feature classes and feature layers. The features, or portion of features, that are common to all inputs (that is, they intersect) will be written to the output feature class.

What is the intersect tool in geoprocessing? ›

"Intersect" computes the geometric intersection of two layers and creates a new layer only containing the features in the common area of the two layers. The attribute table of the new layer lists the data of the two layers.

References

Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 6486

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.