Intersection between two 3D lines

BlitzMax Forums/BlitzMax Programming/Intersection between two 3D lines

JoshK(Posted 2008) [#1]
I know two lines intersect, but I have to find the position where they do. Anyone have some code for this?

--EDIT--

I figured it out. This doesn't check for identical lines, but it works for what I need:

	Method Intersects:TVec3( t:TLine,tolerance#=0.001 )
		Local wx#=x-t.x
		Local wy#=y-t.y
		Local wz#=z-t.z
		Local a#=dx*dx+dy*dy+dz*dz
		Local b#=dx*t.dx+dy*t.dy+dz*t.dz
		Local c#=t.dx*t.dx+t.dy*t.dy+t.dz*t.dz
		Local d#=dx*wx+dy*wy+dz*wz
		Local e#=t.dx*wx+t.dy*wy+t.dz*wz
		Local q#=a*c-b*b
		Local st#=b*e-c*d
		Local tt#=a*e-b*d
		Local tx#=wx+(st*dx-tt*t.dx)/q
		Local ty#=wy+(st*dy-tt*t.dy)/q
		Local tz#=wz+(st*dz-tt*t.dz)/q
		If tolerance<>-1
			If tx*tx+ty*ty+tz*tz>=tolerance*tolerance Return
		EndIf	
		tx#=wx+(st*dx)/q
		ty#=wy+(st*dy)/q
		tz#=wz+(st*dz)/q
		Return vec3(tx,ty,tz).plus(vec3(t.x,t.y,t.z))
	EndMethod