How to intersect these lines?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!