Line Intersection from parametric equation
- by Sidar
I'm sure this question has been asked before. However, I'm trying to connect the dots by translating an equation on paper into an actual function. I thought It would be interesting to ask here instead on the Math sites (since it's going to be used for games anyway ).
Let's say we have our vector equation :
x = s + Lr;
where x is the resulting vector, s our starting point/vector. L our parameter and r our direction vector.
The ( not sure it's called like this, please correct me ) normal equation is :
x.n = c;
If we substitute our vector equation we get:
(s+Lr).n = c.
We now need to isolate L which results in
L = (c - s.n) / (r.n);
L needs to be 0 < L < 1. Meaning it needs to be between 0 and 1.
My question:
I want to know what L is so if I were to substitute L for both vector equation (or two lines) they should give me the same intersection coordinates. That is if they intersect.
But I can't wrap my head around on how to use this for two lines and find the parameter that fits the intersection point.
Could someone with a simple example show how I could translate this to a function/method?