Possible Duplicate:
How do you detect where two line segments intersect?
Given two points a
and b
plus two vectors v
and u
I want to find a third point c
, which is the point of intersection in the following manner:
vector2 intersection(vector2 a, vector2 v, vector2 b, vector2 u)
{
float r, s;
a + r * v = b + s * u;
r * v - s * u = b - a
r * v.x - s * u.x = b.x - a.x
r * v.y - s * u.y = b.y - a.y
}
Is there any other way than using gaussian elimination to solve this system? Or is this the best (or at least an acceptable) way to handle this?
EDIT:
Definition of vector2
typedef union vector2
{
float v[2];
struct { float x, y; };
} vector2;
a
and b
are also of type vector2
, because the only difference between a point and a vector is in the the way it is transformed by an affine transformation.