Find intersection point between two plotted lines (2024)

6 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Mark Sc am 18 Apr. 2023

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines

Bearbeitet: Star Strider am 18 Apr. 2023

  • data_tangent.xlsx

In MATLAB Online öffnen

Hi all,

I have been trying to find an intersection point between two plotted lines however, I used several functions but it doesnot work.. usually the output is 2*0 empty double matrix ... Actually i need the number of intersection ... ?

here is the code and attached are the data

clearvars

clc;

close all

Data = readmatrix('data_tangent.xlsx')

x = Data(:,1);

y = Data(:,2);

[ymax,idx] = max(y);

Binit = x(1:5) \ y(1:5)

Bymax = x(idx) \ y(idx)

Line_init = x*Binit;

Line_initv = Line_init <= ymax;

Line_ymax = x*Bymax;

Line_ymaxv = Line_ymax <= ymax;

figure

plot(x, y)

hold on

plot([0;x(Line_ymaxv)], [0;Line_ymax(Line_ymaxv)], '-r')

hold off

grid

axis('equal')

xlabel('X')

ylabel('Y')

axis([0 max(x) 0 max(y)])

x1=x(Line_ymaxv)

y1=Line_ymax(Line_ymaxv)

P=InterX([x;y],[x1;y1])

The function i used is from "https://www.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections"

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Antworten (2)

Star Strider am 18 Apr. 2023

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#answer_1218238

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#answer_1218238

The code I wrote for your previous post, Plot tangent line on part of the curve is designed as requested to have only one intersection, that being at the origin, since both tangent lines were requested to go through the origin, at least as I understood it.

How else would you want to define the two tangent lines?

2 Kommentare

Keine anzeigenKeine ausblenden

Mark Sc am 18 Apr. 2023

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711153

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711153

@Star Strider

Thank you for your feedback,

just one intersect point thats' what I wanna ...

I just wanna a code to let me know the intersection point value

Thank you once again

Star Strider am 18 Apr. 2023

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711163

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711163

Bearbeitet: Star Strider am 18 Apr. 2023

In MATLAB Online öffnen

  • data_tangent.xlsx

My pleasure!

The two lines I plotted (only one is shown here) both intersect at the origin, since that is how they were requested and designed. The intersection with the curve is designed to be at ‘ymax’ with the x-coordinate of that intersection being ‘x(idx)’, so nothing further needs to be computed.

% clearvars

% clc;

% close all

format long

Data = readmatrix('data_tangent.xlsx')

Data = 13042×2

1.980321668300000 7.370000000000000 1.982328936500000 7.350000000000000 1.985318034200000 7.380000000000000 1.987310766000000 7.400000000000000 1.990343472900000 7.310000000000000 1.993270790900000 7.510000000000000 1.995263522700000 7.530000000000000 1.997299863700000 7.430000000000000 2.000270790900000 7.510000000000000 2.002187206600000 7.740000000000000

x = Data(:,1);

y = Data(:,2);

[ymax,idx] = max(y);

Binit = x(1:fix(idx/4)) \ y(1:fix(idx/4))

Binit =

3.644815761434447

Bymax = x(idx) \ y(idx)

Bymax =

3.216013064246002

Line_init = x*Binit;

Line_initv = Line_init <= ymax;

Line_ymax = x*Bymax;

Line_ymaxv = Line_ymax <= ymax;

Intersection_x = interp1(Line_init-Line_ymax, x, 0, 'linear','extrap')

Intersection_x =

2.273736754432321e-13

Intersection_y = interp1(x, Line_init, Intersection_x, 'linear','extrap')

Intersection_y =

9.094947017729282e-13

Intersection = [Intersection_x, Intersection_y] % Desired Result

Intersection = 1×2

1.0e-12 * 0.227373675443232 0.909494701772928

figure

plot(x, y)

hold on

plot([0;x(Line_ymaxv)], [0;Line_ymax(Line_ymaxv)], '-r')

plot([0;x(Line_initv)], [0;Line_init(Line_initv)], '-r')

hold off

grid

axis('equal')

xlabel('X')

ylabel('Y')

axis([0 max(x) 0 max(y)])

Find intersection point between two plotted lines (5)

% x1=x(Line_ymaxv)

% y1=Line_ymax(Line_ymaxv)

% P=InterX([x;y],[x1;y1])

EDIT — (18 Apr 2023 at 20:03)

Added ‘Intersection’ calculation and result using interp1 to calculate the coordinates.

.

Melden Sie sich an, um zu kommentieren.

Cameron am 18 Apr. 2023

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#answer_1218263

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#answer_1218263

Bearbeitet: Cameron am 18 Apr. 2023

In MATLAB Online öffnen

Looks like a stress-strain curve. Depending on the material, you could adjust the variable I named cutoff to 0.3*ymax or whatever you want. This code takes the first intersection of the stress-strain curve and interpolates the value for yield.

clearvars

clc;

close all

Data = readmatrix('data_tangent.xlsx')

x = Data(:,1);

y = Data(:,2);

[ymax,idx] = max(y);

Binit = x(1:5) \ y(1:5);

Bymax = x(idx) \ y(idx);

Line_init = x*Binit;

Line_initv = Line_init <= ymax;

Line_ymax = x*Bymax;

Line_ymaxv = Line_ymax <= ymax;

Line_y = Line_ymax(Line_ymaxv);

trunc_x = x(1:find(Line_ymaxv,1,'last'));

trunc_y = y(1:find(Line_ymaxv,1,'last'));

ii = length(trunc_y);

cutoff = 0.5*ymax; %you can adjust this

SaveMe = [];

while trunc_y(ii) > cutoff

if (Line_y(ii) > trunc_y(ii) && Line_y(ii-1) <= trunc_y(ii-1)) | ...

(Line_y(ii) < trunc_y(ii) && Line_y(ii-1) >= trunc_y(ii-1))

SaveMe = [SaveMe;ii];

end

ii = ii - 1;

end

m1 = polyfit(x(SaveMe(end)-1:SaveMe(end)),y(SaveMe(end)-1:SaveMe(end)),1);

m2 = polyfit(x(SaveMe(end)-1:SaveMe(end)),Line_y(SaveMe(end)-1:SaveMe(end)),1);

x_cross = (m2(2) - m1(2))/(m1(1) - m2(1));

y_cross = m1(1)*x_cross + m1(2);

figure

plot(x, y)

hold on

plot([0;x(Line_ymaxv)], [0;Line_ymax(Line_ymaxv)], '-r')

scatter(x_cross,y_cross,'filled')

grid

axis('equal')

xlabel('X')

ylabel('Y')

axis([0 max(x) 0 max(y)])

hold off

3 Kommentare

1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden

Mark Sc am 18 Apr. 2023

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711148

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711148

Bearbeitet: Mark Sc am 18 Apr. 2023

@Cameron

Thank you for your answer,

I meant if I already have a two lines plotted so I just wanna know the point of intersection ..

So would you able to help me ?

Thank you very much

Cameron am 18 Apr. 2023

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711168

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711168

The answer is in the code I provided as x_cross and y_cross.

Mark Sc am 18 Apr. 2023

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711233

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1949258-find-intersection-point-between-two-plotted-lines#comment_2711233

@Cameron

Thank you Cameron, but what If I already have my own x and y

x1_y1 as arrays.....

I would appreciate if I can just enter these arrays and got the point of intersection..

Thanks,

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABApp BuildingDevelop Apps Using App Designer

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Tags

  • vectorization
  • plot
  • array
  • find

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Find intersection point between two plotted lines (10)

Find intersection point between two plotted lines (11)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

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

Europa

  • 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)

Asien-Pazifik

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

Kontakt zu Ihrer lokalen Niederlassung

Find intersection point between two plotted lines (2024)

FAQs

Find intersection point between two plotted lines? ›

Finding a Point Algebraically

How to find the point of 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.

What is the formula for the intersection of lines? ›

Point of intersection means the point at which two lines intersect. These two lines are represented by the equation a1x + b1y + c1= 0 and a2x + b2y + c2 = 0, respectively. Given figure illustrate the point of intersection of two lines. We can find the point of intersection of three or more lines also.

How do you find the point on the intersection line of two planes? ›

To find a point on the line, you set one of the coordinates in the equations of both planes equal to zero and solve the system of equations you end up with. Note! If you set z = 0 and the line of intersection is perpendicular to the z -axis, no points on the line have z = 0 .

How do you find the point of intersection of two trend lines? ›

If you have the equations of the lines, then just subtract one from the other, find the zero of the difference for the x coordinate and just calculate the linear function for each of the lines to get the single y coordinate.

How to find the intersection of two lines vectors? ›

To find the point of intersection of these two lines, we must find a point P that lies on both lines. At the point of intersection the coordinates for L1 will equal the coordinates for L2. This means there exist values of s and t such that the x, y and z coordinates of the two lines are equal.

What is the intersection of two graphs in graph theory? ›

We define intersection graph as follows. A graph G = ( V , E ) is called an intersection graph for a finite family F of a non-empty set if there is a one-to-one correspondence between F and V such that two sets in F have non-empty intersection if and only if their corresponding vertices in V are adjacent.

How to calculate intersection? ›

We can find the probability of the intersection of two independent events as, P(A∩B) = P(A) × P(B), where, P(A) is the Probability of an event “A” and P(B) = Probability of an event “B” and P(A∩B) is Probability of both independent events “A” and "B" happening together.

What is the point of intersection of the graphs called? ›

The point of intersection (0, 0) is called the origin. In an ordered pair, the x-coordinate is always listed first and the y-coordinate second. Intercept. The x-intercept is the point at which a graph crosses the x-axis. The y-intercept is the point at which the graph crosses the y-axis.

What is line intersection theorem? ›

Theorem 1: If two lines intersect, then they intersect in exactly one point.

How do you find the point of intersection when given two lines? ›

Point of Intersection Formula
  1. 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. ...
  2. a1x+b1y+c1=0 and a2x+b2y+c2=0.
  3. x= (b1c2-b2c1)/(a1b2-a2b1)
  4. y=(c1a2-c2a1)/(a1b2-a2b1)
  5. (x, y) = ((b1c2-b2c1)/(a1b2-a2b1), (c1a2-c2a1)/(a1b2-a2b1))

What is the intersection of two intersecting lines? ›

Intersection of two lines is a point at which both lines meet. When two lines share a common point, they are called intersecting lines. This common point that exists on all intersecting lines is called the point of intersection. The two non-parallel straight lines which are co-planar will have an intersection point.

How to find the point of intersection between two vectors? ›

By setting the values of x, y and z for these equations equal to one another, a value for both of the parameters can be found. These values can then be substituted back into the relevant vector equation to discover the point of intersection.

How to 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}. Let us earn more about the properties of the intersection of sets along with examples.

Top Articles
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 6401

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.