Anyway, this is it:
Code: Select all
Type Point2d
x as single
y as single
End Type
Type Line2d
p1 as Point2d
p2 as Point2d
End Type
Sub Line_Intersection( byval a as Line2d, byval b as Line2d, byref intersect as Point2d )
dim as single x1, y1, z1, x2, y2, z2, det_inv, m1, m2
if ( a.p1.x - a.p2.x ) <> 0 then
m1 = ( a.p2.y - a.p1.y ) / ( a.p2.x - a.p1.x )
else
m1 = Exp( 1 ) + 10
end if
if ( b.p1.x - b.p2.x ) <> 0 then
m2 = ( b.p2.y - b.p1.y ) / ( b.p2.x - b.p1.x )
else
m2 = Exp( 1 ) + 10
end if
x1 = m1
x2 = m2
y1 = -1
y2 = -1
z1 = ( a.p1.y-m1*a.p1.x )
z2 = ( b.p1.y-m2*b.p1.x )
det_inv = 1/(x1*y2 - x2*y1)
intersect.x = ((y1*z2 - y2*z1)*det_inv)
intersect.y = ((x2*z1 - x1*z2)*det_inv)
End Sub
Any improvements are welcome (even changing the UDTs or whatever...as long as it is more efficient or speed)
thanks,
Oz