2D line intersection. Beat this?

Miscellaneous Forums/General Discussion/2D line intersection. Beat this?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Function RayIntersect(ax#,ay#,bx#,by#,cx#,cy#,dx#,dy#,rx# Var, ry# Var)
	
	Local u_b#  = (dy - cy) * (bx - ax) - (dx - cx) * (by - ay)

	If ( u_b <> 0 ) 
		Local ua_t# = (dx - cx) * (ay - cy) - (dy - cy) * (ax - cx)
		Local ub_t# = (bx - ax) * (ay - cy) - (by - ay) * (ax - cx)
		Local ua# = ua_t / u_b
		Local ub# = ub_t / u_b

		If ( 0 <= ua And ua <= 1 And 0 <= ub And ub <= 1 ) 
			rx# = ax + ua * (bx - ax)
			ry# = ay + ua * (by - ay)
			Return True
		EndIf 
	EndIf
EndFunction

rx# and ry# are the points of intersection