Is there a way to find the intersection of lines in 3D space or the points on the lines that are closest to each other without using a guess and check method? For example, I have the code
function intersection(xi1, yi1, zi1, xv1, yv1, zv1, xi2, yi2, zi2, xv2, yv2, zv2, var)
t1 = 0
t2 = 0
x = 0
y = 0
z = 0
mind = 9999
retu = 0
for t1 = -99 to 99
for t2 = -99 to 99
x1 = xi1 + ((t1/10) * xv1)
y1 = yi1 + ((t1/10) * yv1)
z1 = zi1 + ((t1/10) * zv1)
x2 = xi2 + ((t2/10) * xv2)
y2 = yi2 + ((t2/10) * yv2)
z2 = zi2 + ((t2/10) * zv2)
if mind > distance(x1, y1, z1, x2, y2, z2)
mind = distance(x1, y1, z1, x2, y2, z2)
x = (x1 + x2)/2
y = (y1 + y2)/2
z = (z1 + z2)/2
endif
next
next
if var = 0
retu = x
endif
if var = 1
retu = y
endif
if var = 2
retu = z
endif
endfunction retu
the parameters for the function are a point on each line and the components of the vector on that line for both lines. t1 and t2 are the varibales determining the location on each respective line. "mind" is the minimum distance between the lines. Distance() is a function to find distance between points. As you can see, this method is purely guess and check. However, is has limited accuracy and causes my cpu to lag a little bit.
My question: Is there another method to find intersections of lines, or a better was to use guess and check?
pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342177067... and yet I still have a life.