For a program I am writing, I am trying to find the intersection of (2) 3-dimensional lines, each line represented by a class that is an array of (2) 3-dimensional points.
That is, each line is described by two points. The points are, of course, points on the line, but not necessarily the endpoints since the line is considered infinite.
At any rate, I am looking for a simple way to calculate the point at which the lines intersect (I can already check (true/false) for intersection). I have tried many approaches, including:
(1) Algrebraic solution using linear relationship of x,y,z per line--this is problematic because to calculate y(x) or z, for examples, you need the ratio of the two using the endpoints (a partial slope, so to speak) and the ratio can be infinite (x, y, or z can be independent of the other variables, such as a line along the x-axis would have no dependence on y or z. There are something line 64 special cases I'd have to test for.)
(2) Solution by linear systems of equations of cross products (without going into too much detail, this didn't work for me, either)
(3) Solution using unit vectors along the lines and from one line to the other along with the Law of Sines to calculate the distance from one of the points to the point of intersection (This is close to working, but it has problems, too.)
Does anyone know of any code out there that would perform this task or of a simple mathematical way to calculate this simpler? Any help would be greatly appreciated.
That is, each line is described by two points. The points are, of course, points on the line, but not necessarily the endpoints since the line is considered infinite.
At any rate, I am looking for a simple way to calculate the point at which the lines intersect (I can already check (true/false) for intersection). I have tried many approaches, including:
(1) Algrebraic solution using linear relationship of x,y,z per line--this is problematic because to calculate y(x) or z, for examples, you need the ratio of the two using the endpoints (a partial slope, so to speak) and the ratio can be infinite (x, y, or z can be independent of the other variables, such as a line along the x-axis would have no dependence on y or z. There are something line 64 special cases I'd have to test for.)
(2) Solution by linear systems of equations of cross products (without going into too much detail, this didn't work for me, either)
(3) Solution using unit vectors along the lines and from one line to the other along with the Law of Sines to calculate the distance from one of the points to the point of intersection (This is close to working, but it has problems, too.)
Does anyone know of any code out there that would perform this task or of a simple mathematical way to calculate this simpler? Any help would be greatly appreciated.