Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been trying to get the intersection point of 2 3D lines (in general, so i can code an algorithm) using the following equations:

$$ x_0 + k_0 a_0 = x_1 + k_1 a_1 \tag{1}$$

$$ y_0 + k_0 b_0 = y_1 + k_1 b_1 \tag{2}$$

$$ z_0 + k_0 c_0 = z_1 + k_1 c_1 \tag{3}$$

where $x,y,z$ are point coordinates and $a,b,c$ direction vector coordinates.

I think the idea is to get $k_0$ or $k_1$ so I can get the point from the line ($l_0$ if i use $k_0$, $l_1$ otherwise) using it's parametric equation.

I've made some tests and if I use equations $(1)$ and $(2)$ I get different results that if I use $(2)$ and $(3)$, so i think i'm doing something wrong...

From $(1)$: $$ k_0 = \frac{x_1-x_0 + k_1a_1}{a_0} \tag{4}$$

from $(2)$: $$ k_1 = \frac{y_0-y_1 + k_0b_0}{b_1} \tag{5}$$

from $(4)$ & $(5)$: $$k_1 = \frac{a_0 (y_0 - y_1) + b_0 (x_1 - x_0)}{a_0 b_1 - b_0 a_1} \tag{6}$$

And from $(1)$ & $(3)$: $$k_1 = \frac{a_0 (z_0 - z_1) + c_0 (x_1 - x_0)}{a_0 c_1 - c_0 a_1} \tag{7}$$

I don't know why, but $(6)$ & $(7)$ get different results for $k_1$...

I'm not controlling divisions by zero because C# returns NaN ($0/0$), -Infinity ($-x/0$), +Infinity ($x/0$) when needed, so I assume that if there is no intersection there would be some division by zero or something like that, right?

Any idea of whats wrong?

Thanks a lot!!

share|cite|improve this question
up vote 1 down vote accepted

The problem is quite simplyy that if you take 2 lines in a 3D space they usually do not intersect (think about it!). So it's perfectly normal to get different results for $k_1$ : it simply means that your lines are not coplanar (you will only get a divide by zero error if they happen to be parallel).

share|cite|improve this answer
That explains everything! But that makes me wonder how do I check whether they are coplanar or not... – Xavier Arias Botargues Jul 29 '12 at 12:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.