Login Register
Frontpage Code library Pastebin

LinesIntersect

Author: MetalRain
Added: 9.4.2011 23:48
Edited: 15.4.2011 22:19
Category: Matematiikka

Description

Janojen leikkauksen ja leikkauspisteen laskeva funktio. Leikkauspiste saatavilla IntersX ja IntersY koordinaateista.

Code

Select all
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
Global IntersX As Float, IntersY As Float

Function Lines_Intersect(Ax#, Ay#, Bx#, By#, Cx#, Cy#, Dx#, Dy#)

   Rn# = (Ay#-Cy#)*(Dx#-Cx#) - (Ax#-Cx#)*(Dy#-Cy#)
   Rd# = (Bx#-Ax#)*(Dy#-Cy#) - (By#-Ay#)*(Dx#-Cx#)

   If Rd# = 0
       Return False    
   Else
       Sn# = (Ay#-Cy#)*(Bx#-Ax#) - (Ax#-Cx#)*(By#-Ay#)
       Intersection_AB# = Rn# / Rd#
       Intersection_CD# = Sn# / Rd#        
       If Intersection_AB#>1 Or Intersection_CD#>1 Or Intersection_AB#<0 Or Intersection_CD#<0 Then Return False
       IntersX = Ax# + Intersection_AB#*(Bx#-Ax#)
       IntersY = Ay# + Intersection_AB#*(By#-Ay#)    
       Return True        
   EndIf

End Function

Comments

No comments. You can be first!

Leave a comment

You must be logged in to comment.