For Programmers: Free Programming Magazines  


Home > Archive > Matlab > November 2005 > Intersection of two lines









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Intersection of two lines
Mark Mendez

2005-11-17, 3:59 am

I am trying to write a code that solves for the intersection of two
lines as their slopes and y-intercepts change indepently of each
other. i was wondering if anyone knew of a easy way to do this. Right
now i have everything in a table and i want it to calculate all the
possible solutions into a mesh that i can plot in 3D based on the x
and y value of the intersection.
nma@12000.org

2005-11-17, 3:59 am

Mark Mendez wrote:
> I am trying to write a code that solves for the intersection of two
> lines as their slopes and y-intercepts change indepently of each
> other. i was wondering if anyone knew of a easy way to do this. Right
> now i have everything in a table and i want it to calculate all the
> possible solutions into a mesh that i can plot in 3D based on the x
> and y value of the intersection.


intersection point is the solution to the 2 lines equations. The
solution is (x,y).
So, set up Ax=c and solve for 'x', where 'x' here is the (x,y) point,
using Matlab \ operator.

example:

%y=m1 x + c1
%y=m2 x + c2

m1=.5;
m2=.3;
c1=0;
c2=1;

c=[c1;c2];

A=[1 -m1;1 -m2]

intersectionPoint = A\c

Nasser

Mark

2005-11-17, 7:06 pm

nma wrote:
>
>
> Mark Mendez wrote:
> two
each[color=darkred]
> Right
> the
the[color=darkred]
> x
>
> intersection point is the solution to the 2 lines equations. The
> solution is (x,y).
> So, set up Ax=c and solve for 'x', where 'x' here is the (x,y)
> point,
> using Matlab \ operator.
>
> example:
>
> %y=m1 x + c1
> %y=m2 x + c2
>
> m1=.5;
> m2=.3;
> c1=0;
> c2=1;
>
> c=[c1;c2];
>
> A=[1 -m1;1 -m2]
>
> intersectionPoint = A\c
>
> Nasser
>
>


Why does A = [1 -m1;1 -m2]. I do not understand why it is a 2x2
matrix and why a value of 1?
minikitty

2005-11-17, 7:06 pm

Maybe this is easier for you?
y - m1 x = c1
y - m2 x = c2

A [y;x] = [c1; c2] ===> [y;x] = A\[c1;c2]

N.P.Nagendra Rao

2005-11-28, 3:58 am

minikitty wrote:
>
>
> Maybe this is easier for you?
> y - m1 x = c1
> y - m2 x = c2
>
> A [y;x] = [c1; c2] ===> [y;x] = A\[c1;c2]
>
>

my answer is :

l1=[a1 b1 c1] l2=[a2 b2 c2]
matlab programme is :

P=intersection(l1,l2):

a=A(1);b=A(2);c=A(3);
p=B(1);q=B(2);z=B(3);

d=p*b-a*q;
x= (q*c-b*z)/d;
y= (a*z-p*c)/d;
P(1)=x;
P(2)=y;
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com