How to intersect these lines?

2 ビュー (過去 30 日間)
Emmanuel
Emmanuel 2014 年 5 月 29 日
コメント済み: Emmanuel 2014 年 5 月 29 日
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);

回答 (1 件)

David Sanchez
David Sanchez 2014 年 5 月 29 日
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 件のコメント
David Sanchez
David Sanchez 2014 年 5 月 29 日
syms x
x=solve(x*ma + na == x*mb + nb)
x=
12/7
y=x*ma+na
y =
19/7
Emmanuel
Emmanuel 2014 年 5 月 29 日
Hi! Thankyou for your reply. With regard to your reply for the previous post, the code is here:
for i=1:1:3
[A] = input('enter the 1st co-ordinate of the line');
[B] = input('enter the 2nd co-ordinate of the line');
xlim = [-10 10];
m = (B(2)-B(1))/(A(2)-A(1));
n = B(2)*m - A(2);
y1 = m*xlim(1) + n;
y2 = m*xlim(2) + n;
hold on
line([xlim(1) xlim(2)],[y1 y2])
plot(y1,y2)
hold off
end
%SAMPLE OUTPUT
%enter the 1st co-ordinate of the line[1,5]
%enter the 2nd co-ordinate of the line[3,2.5]
%enter the 1st co-ordinate of the line[3,1]
%enter the 2nd co-ordinate of the line[4,1]
%enter the 1st co-ordinate of the line[4,1]
%enter the 2nd co-ordinate of the line[4.5,5.8]
When I plot this on a paper and the output graph by matlab varies a lot. if i change the xlim to [0 20] , the lines do not intersect at all. Why does the output from matlab varies from that of the paper graph even if I use the same scale? Ihave attached the output plot. Can we like rectify it?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by