Detecting intersection of two lines in n-dimensional space
This seems to be a very difficult subject to google for, and I only really know how to do this in 2-dimensions.
What I'm looking to do is calculate the point at which two lines in N dimensions intersect. N could be 2, 3, 4 or any other value, which is what makes this so complicated to get my head around.
Any help is greatly appreciated, and I would appreciate also if any answers are given in the smallest pieces possible, big equations may be great for expressing something in one line, but they can be a nightmare to read :)
Thanks
Re: Detecting intersection of two lines in n-dimensional space
In order to solve a problem like this, it is best to use matrices. For convenience sake, everything following this will follow these basic rules:
- A very small number behind a letter 'x' is a subscript. I prefer this to the x,y,z concept for simplicity's sake at higher 'n'.
- If you see something like this:
|3 2|
|2 1|
|1 7|
It represents a matrix. - An italicised variable represents a vector
- (-1) after a matrix variable means that it is being inverted
As a warmup, let's consider a basic 2-dimensional system of equations and solve it using matrices:
x1+2x2=10
3x1+7x2=13
We can use the following matrix to represent the above equation:
|1 2||x1|=|10|
|3 7||x2| |13|
The 2x2 matrix on the left is called the coefficient matrix(A). To solve for x1 and x2 we obviously need to 'move' the coefficient matrix to the right side of the equation. Since there is no such thing as division in matrices, we can instead multiply both sides by the inverse of the coefficient matrix.
I'm not going to explain how to get the inverse of a matrix as you should know this if you are at the level you are at. Solving will get the solution:
|x1|=| 44|
|x2| |-17|
Meaning that two lines will intersect at x1=44 and x2=-17
We can expand this solution for any 'n' number of dimensions, such as the following:
a1x1 + a2x2+…+anxn = a0
b1x1+ b2x2+…bnxn = b0
… … … … …………
n1x1+n2x2+…nnxn = n0
We will store the constants in a matrix called the solution matrix(S), as follows:
|a0|
|b0|
|...|
|n0|
And we'll create a vector matrix(v) to store our variables:
|x1|
|x2|
|...|
|xn|
Notice that if we multiply the matrix A by the vector, v, we get the set of original linear equation in an “n by 1” vector. Then if we have two matrices equal to each other, entries must be equal, so we have the complete set of linear equations represented by the matrix equation:
Av=S
If A is invertible, then this equation can be solved in the obvious way—multiply both sides on the left by the inverse matrix of A, A(-1). This gives us:
(A(-1)A)v = A(-1)S
v = A(-1)S
This will work for any number of dimensions. Hope it helped!
Re: Detecting intersection of two lines in n-dimensional space
Excellent answer! Thank you very much Maximilian, your explanation has helped considerably. I had bits and pieces of this but seeing it explained clearly let's me see what I was doing wrong; which is why I neglected to post what I'd done so far as it was a complete mess that only mathematical symbols in the wrong hands can achieve!
Part of the trouble is that Google comes up mostly with computing solutions that (while probably faster) only really work for a particular set of dimensions, or rely on another, also quite complex, algorithm in order to work.
Anyway, thank you very much for your answer.
Re: Detecting intersection of two lines in n-dimensional space
Technically the method Max described gives the intersection (if it's unique) of n (hyper)-planes instead of 2 lines. That is, in 3-D, a1*x1+a2*x2+a3*x3=c0 represents a plane--not a line--and the matrix used to solve for each xi geometrically finds the intersection of 3 of these planes. It seems like this was what you wanted anyway :D
If not, though, to "[detect] the intersection of two lines in n-dimensional space," you would probably just solve the parametric equations that describe the lines simultaneously. I'd be happy to go into more detail if you need--just thought I'd clarify the wording and underlying concepts behind these intersections :)
Re: Detecting intersection of two lines in n-dimensional space
Yea :) I know that it's actually an intersection of hyperplanes. The concept of a line doesn't work in more than 3 dimensions really, but for the sake of simplicity I didn't push the point.