# Thread: Intersection of two lines - simultaneous equations problem

1. ## Intersection of two lines - simultaneous equations problem

Hi,

I'm currently teaching myself a lot of math while working through a book on maths and physics for game programmers. I've had to start from scratch and currently have worked through from linear algebra, trig and now vectors. I'm afraid the book that I have skirts over a lot of detail, which I'm not happy with, so I often have to trawl the Internet for further explanation.

I've hit on a problem that I can't find the answer for so hopefully someone on this forum could point me in the right direction?

So, I'm going through the chapter on vectors and looking at using algebra with vectors to calculate where 2 lines intersect. There a four position vectors (a,b,c,d) of the four points A, B, C, D. These are drawn in a figure, where a line from A to B crosses over a line from C to D. The book lists two linear simultaneous equations for solving the problem:

1. t(b1 - a1) + s(c1 - d1) = c1 - a1
2. t(b2 - a2) + s(c2 - d2) = c2 - a2

For the life of me, I can't solve these equations. I don't have to, but I'd like to as I want to know why it works.

Can anyone help me get started, I can solve t for equation 1 and then substitute t in equation 2 to try and solve s, but then I'm stuck!

Thanks in advance for anyone who can help.

GM

2. Originally Posted by GamerMath
Hi,

I'm currently teaching myself a lot of math while working through a book on maths and physics for game programmers. I've had to start from scratch and currently have worked through from linear algebra, trig and now vectors. I'm afraid the book that I have skirts over a lot of detail, which I'm not happy with, so I often have to trawl the Internet for further explanation.

I've hit on a problem that I can't find the answer for so hopefully someone on this forum could point me in the right direction?

So, I'm going through the chapter on vectors and looking at using algebra with vectors to calculate where 2 lines intersect. There a four position vectors (a,b,c,d) of the four points A, B, C, D. These are drawn in a figure, where a line from A to B crosses over a line from C to D. The book lists two linear simultaneous equations for solving the problem:

1. t(b1 - a1) + s(c1 - d1) = c1 - a1
2. t(b2 - a2) + s(c2 - d2) = c2 - a2

For the life of me, I can't solve these equations. I don't have to, but I'd like to as I want to know why it works.

Can anyone help me get started, I can solve t for equation 1 and then substitute t in equation 2 to try and solve s, but then I'm stuck!

Thanks in advance for anyone who can help.

GM
The substitution method should work, but the elimination method is more commonly used.

Say you want to eliminate the $\displaystyle t$ values - you need to multiply all of equation 1 by $\displaystyle (b_2 - a_2)$ and multiply all of equation 2 by $\displaystyle (b_1 - a_1)$. This will make the coefficients of $\displaystyle t$ equal, and you should then be able to eliminate $\displaystyle t$ and solve for $\displaystyle s$. Then solve for $\displaystyle t$.

3. Originally Posted by Prove It
The substitution method should work, but the elimination method is more commonly used.

Say you want to eliminate the $\displaystyle t$ values - you need to multiply all of equation 1 by $\displaystyle (b_2 - a_2)$ and multiply all of equation 2 by $\displaystyle (b_1 - a_1)$. This will make the coefficients of $\displaystyle t$ equal, and you should then be able to eliminate $\displaystyle t$ and solve for $\displaystyle s$. Then solve for $\displaystyle t$.
Hey, thanks for taking the time to answer this. I'm a bit closer now, but not quite there, due to being a bit of a newb at linear algebra.

So the equations become:

1.) t(b1 - a1)(b2 - a2) + s(c1 - d1)(b2 - a2) = c1 - a1(b2 - a2)
2.) t(b2 - a2)(b1 - a1) + s(c1 - d1)(b1 - a1) = c2 - a2(b1 - a1)

I then try to subtract 2 from 1 and can see that t's are eliminated to get:

s(c1 - d1)(b2 - a2) - s(c1 - d1)(b1 - a1) = c1 - a1(b2 - a2) - c2 - a2(b1 - a1)

It's the next bit where I come unstuck. I end up with

s + s = c1 - a1(b2 - a2) - c2 - a2(b1 - a1) / (c1 - d1)(b2 - a2) + (c1 - d1)(b1 - a1)

Any more hints much appreciated

GM

4. Originally Posted by GamerMath
Hey, thanks for taking the time to answer this. I'm a bit closer now, but not quite there, due to being a bit of a newb at linear algebra.

So the equations become:

1.) t(b1 - a1)(b2 - a2) + s(c1 - d1)(b2 - a2) = (c1 - a1)(b2 - a2)
2.) t(b2 - a2)(b1 - a1) + s(c1 - d1)(b1 - a1) = (c2 - a2)(b1 - a1)

I then try to subtract 2 from 1 and can see that t's are eliminated to get:

s(c1 - d1)(b2 - a2) - s(c1 - d1)(b1 - a1) = (c1 - a1)(b2 - a2) - (c2 - a2)(b1 - a1)
Correct up to here with the necessary brackets. Now you need to expand all the brackets, so that you can collect the like terms of s.

5. Could you factor the right-hand side like so

$s\left[(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)\right]$

and then divide by the equation by second factor? Or will you eventually have to expand anyway?

6. Originally Posted by Prove It
Correct up to here with the necessary brackets. Now you need to expand all the brackets, so that you can collect the like terms of s.
I'm probably doing something horribly wrong here. When I expand the brackets I get:

sc1b1 - sc1a2 - sd1b2 + sd1a2 - sc1b1 - sc1a1 - sd1b1 + sd1a1 =
c1b2 - c1a2 - a1b2 + a1a2 - c2b1 -c2a1 - a2b1 +a2a1

Anywhere near? No wonder the author of my book didn't show how to solve them!

7. Looks fine so far, so now you'll see there's a common factor of $\displaystyle s$ on the LHS...

8. Originally Posted by Prove It
Looks fine so far, so now you'll see there's a common factor of $\displaystyle s$ on the LHS...
Thanks for the clue, but I think I need another one

9. Starting here

$s(c_1 - d_1)(b_2 - a_2) - s(c_1 - d_1)(b_1 - a_1) = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

notice the common factor of s of both terms on the right hand side.

$s\left[(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)\right] = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

Does that make sense? If not, then try the following simpler example:

$sa + sb = s(a + b)$

Once you are comfortable with the previous steps, let's return the following equation:

$s\left[(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)\right] = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

Divide both sides of the equation by $(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)$ to solve the equation in terms of $\displaystyle s$.

$s = \dfrac{(c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)}{(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)}$

I don't know if expanding the terms in the numerator and denominator would simplify the solution, so I would leave the solution as is.

10. Originally Posted by NOX Andrew
Starting here

$s(c_1 - d_1)(b_2 - a_2) - s(c_1 - d_1)(b_1 - a_1) = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

notice the common factor of s of both terms on the right hand side.

$s\left[(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)\right] = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

Does that make sense? If not, then try the following simpler example:

$sa + sb = s(a + b)$

Once you are comfortable with the previous steps, let's return the following equation:

$s\left[(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)\right] = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

Divide both sides of the equation by $(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)$ to solve the equation in terms of $\displaystyle s$.

$s = \dfrac{(c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)}{(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)}$

I don't know if expanding the terms in the numerator and denominator would simplify the solution, so I would leave the solution as is.
I only suggested expanding everything so that only the important common factor would stand out...

11. Two lines never intersect unless different slope unless indefinite number of solutions.

12. Originally Posted by NOX Andrew
Starting here

$s(c_1 - d_1)(b_2 - a_2) - s(c_1 - d_1)(b_1 - a_1) = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

notice the common factor of s of both terms on the right hand side.

$s\left[(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)\right] = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

Does that make sense? If not, then try the following simpler example:

$sa + sb = s(a + b)$

Once you are comfortable with the previous steps, let's return the following equation:

$s\left[(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)\right] = (c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)$

Divide both sides of the equation by $(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)$ to solve the equation in terms of $\displaystyle s$.

$s = \dfrac{(c_1 - a_1)(b_2 - a_2) - (c_2 - a_2)(b_1 - a_1)}{(c_1 - d_1)(b_2 - a_2) - (c_1 - d_1)(b_1 - a_1)}$

I don't know if expanding the terms in the numerator and denominator would simplify the solution, so I would leave the solution as is.
Thanks for this. I can see exactly why it works now. As I said, I'm a newbie. I've covered factoring expressions, but couldn't see the wood for the trees with this one even though I was being pointed towards it!

13. Originally Posted by Prove It
I only suggested expanding everything so that only the important common factor would stand out...
Thanks for your help. I can see exactly why you did it now!