How to intersect these lines?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all! Given below is the code for plottong three lines given any two arbitrary points per line. I have to find the vertices of the intersection points of these lines. I am getting the plot , but they are not intersecting. I have attached the image below, please help!!
%For Line 1
[x1] = input('Enter the value of 1st coord');
[y1] = input('Enter the value of 1st coord');
t = linspace(0,1);
xa = x1(1)+ (y1(1)-x1(1))*t;
ya = y1(1) + (y1(2)-x1(1))*t;
%For Line 2
[x2] = input('Enter the value of 1st coord');
[y2] = input('Enter the value of 1st coord');
u = linspace(0,1);
xb = x2(1)+ (y2(1)-x2(1))*u;
yb = y2(1) + (y2(2)-x2(1))*u;
%For Line 3
[x3] = input('Enter the value of 1st coord');
[y3] = input('Enter the value of 1st coord');
v = linspace(0,1);
xc = x3(1)+(y3(1)-x3(1))*v;
yc = y3(1)+(y3(2)-x3(1))*v;
plot(xa,ya,xb,yb,xc,yc);
0 commentaires
Réponses (1)
David Sanchez
le 29 Mai 2014
I give you the code for two lines, you extend it to three (do it by pairs
if true
% code
end):
%For Line 1
[x1] = [2 3];%input('Enter the value of 1st coord');
[y1] = [3 4];%input('Enter the value of 1st coord');
ma = (y1(2)-y1(1))/(x1(2)-x1(1));
na = y1(1) - ma*x1(1);
%For Line 2
[x2] = [2 4];%input('Enter the value of 1st coord');
[y2] = [2 -3];%input('Enter the value of 1st coord');
mb = (y2(2)-y2(1))/(x2(2)-x2(1));
nb = y2(1) - mb*x2(1);
syms x
solve(x*ma + na == x*mb + nb)
ans =
12/7
2 commentaires
David Sanchez
le 29 Mai 2014
syms x
x=solve(x*ma + na == x*mb + nb)
x=
12/7
y=x*ma+na
y =
19/7
Voir également
Catégories
En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!