404 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Swati Umamaheshwaran il 17 Set 2017
Risposto: Preetham Manjunatha il 8 Feb 2022
I need to plot the lines x+y=3 and x-y= -1 and find their point of intersection. I know that to plot the lines I could use 'fplot'. How can I find the coordinates of their intersection and plot it? Please help.
0 Commenti Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Accedi per commentare.
Accedi per rispondere a questa domanda.
Risposte (5)
Star Strider il 17 Set 2017
Apri in MATLAB Online
Another approach:
xymtx = [1 1; 1 -1];
cv = [3; -1];
xy = xymtx\cv; % Calculate Intercept
xint = xy(2); % X-Value Of Intercept
yint = xy(1); % Y-Value Of Intercept
xyind = [xint - 1, xint + 1]'; % X-Values For Plot
xydep = [cv -xyind.*xymtx(:,2)]; % Y-Values For Plot
figure(1)
plot(xyind, xydep(1,:), xyind, xydep(2,:), '-r')
hold on
plot(xint, yint, 'pg', 'MarkerFaceColor','g', 'MarkerSize',10)
hold off
This is straightforward and relatively simple linear algebra. The ‘xydep’ variable calculates the y-values corresponding to the arbitrary values in ‘xydep’, and is the result of solving ‘[X + Y] = C’ for ‘Y’.
0 Commenti Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Accedi per commentare.
Tutku Oztel il 9 Gen 2019
⋮
Apri in MATLAB Online
Hello,
I'm sharing the function that I wrote to find the intersection points of two lines with their given slope and constant values:
function [x0 y0] = intersectPoints(m1,m2,b1,b2)
% Insersection point of two lines with known slope and constant
% parameters.
% [x0 y0] = intersectPoints(m1,m2,b1,b1)
% where m's are slope, and b's are constants.
% written by Tutku Öztel in 06.01.2019
x0 = (b2-b1)/(m1-m2); %find the x point
y0 = m1*x0+b1;
end
Late though, but still.. Hope it will be helpful! :)
Tutku
2 Commenti Mostra NessunoNascondi Nessuno
Mostra NessunoNascondi Nessuno
José Luis Sandoval il 7 Giu 2020
Link diretto a questo commento
https://it.mathworks.com/matlabcentral/answers/357026-how-to-plot-2-lines-and-find-the-coordinates-of-their-intersection#comment_887846
Usefuil, thanks.
Wai Keong Bryce Wong il 12 Ott 2020
Link diretto a questo commento
https://it.mathworks.com/matlabcentral/answers/357026-how-to-plot-2-lines-and-find-the-coordinates-of-their-intersection#comment_1052126
This is super useful. Thanks for your help!
Accedi per commentare.
Simon Kölbl il 17 Set 2017
Apri in MATLAB Online
I would do it like this:
% define x Axis and evaluate functions
x_points = -5:0.1:5;
function1 = -x+1;
function2 = x+1;
index_intersection = find(function1 == function2);
x_value_intersection = x_points(index_intersection);
y_value_intersection = function1(index_intersection);
% plot functions and intersection point:
curve1 = plot(x_points, function1);
hold on
curve2 = plot(x_points, function2);
intersection = plot(x_value_intersection, y_value_intersection,...
'Marker', '+', 'MarkerSize', 6, 'Color', 'r');
2 Commenti Mostra NessunoNascondi Nessuno
Mostra NessunoNascondi Nessuno
Cyril Okhio il 13 Nov 2018
Link diretto a questo commento
https://it.mathworks.com/matlabcentral/answers/357026-how-to-plot-2-lines-and-find-the-coordinates-of-their-intersection#comment_636946
Sorry it did not work. There are errors in Line 9.
Image Analyst il 5 Giu 2021
Link diretto a questo commento
https://it.mathworks.com/matlabcentral/answers/357026-how-to-plot-2-lines-and-find-the-coordinates-of-their-intersection#comment_1565965
Apri in MATLAB Online
@Cyril Okhio, I think @Simon Kölbl meant this:
clc;% Clear command window.
fprintf('Running %s.m ...\n', mfilename);
clear;% Delete all variables.
close all;% Close all figure windows except those created by imtool.
workspace;% Make sure the workspace panel is showing.
% Define x Axis and evaluate functions
x_points = -5:0.1:5;
function1 = -x_points+1;
function2 = x_points+1;
index_intersection = find(function1 == function2);
x_value_intersection = x_points(index_intersection)
y_value_intersection = function1(index_intersection)
% Plot functions and intersection point:
curve1 = plot(x_points, function1);
hold on
curve2 = plot(x_points, function2);
intersection = plot(x_value_intersection, y_value_intersection,...
'Marker', '+', 'MarkerSize', 20, 'Color', 'r', 'LineWidth', 2);
grid on
caption = sprintf('At intersection, x = %f, y = %f', x_value_intersection, y_value_intersection);
fontSize = 15;
title(caption, 'FontSize', 15);
xlabel('x', 'FontSize', 15);
ylabel('y', 'FontSize', 15);
fprintf('Done running %s.m\n', mfilename);
Accedi per commentare.
Matt J il 5 Giu 2021
Modificato: Matt J il 5 Giu 2021
Apri in MATLAB Online
Using this File Exchange submission,
https://www.mathworks.com/matlabcentral/fileexchange/93470-intersections-of-multiple-2d-lines-or-line-segments
xy=linexlines2D( [1,1,-3].' , [1,-1,1] ); %the intersection point
hold on
fimplicit(@(x,y) x+y-3);
fimplicit(@(x,y) x-y+1);
plot(xy(1),xy(2),'or','MarkerFaceColor','r')
hold off
0 Commenti Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Accedi per commentare.
Preetham Manjunatha il 8 Feb 2022
Here is the link to find the intersection point of two line segments/lines. A fast two line intersection point finder based on the line parametric space. Finds the intersection point between two lines if it exists or else submits NaN. if you need to find the intersection of the multiple line segments, MATLAB's Mapping Toolbox has function polyxpoly - that finds the intersection points for lines or polygon edges.
0 Commenti Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti
Accedi per commentare.
Accedi per rispondere a questa domanda.
Vedere anche
Categorie
MATLABGraphicsGraphics ObjectsGraphics Object Properties
Scopri di più su Graphics Object Properties in Help Center e File Exchange
Tag
- intersection of 2 lines
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Si è verificato un errore
Impossibile completare l'azione a causa delle modifiche apportate alla pagina. Ricarica la pagina per vedere lo stato aggiornato.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Americhe
- 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)
Asia-Pacifico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contatta l’ufficio locale