Linienkollision
Übersicht

![]() |
JustusBetreff: Linienkollision |
![]() Antworten mit Zitat ![]() |
---|---|---|
Liefert True zurück, wenn sich zwei Strecken (keine Geraden!) schneiden.
Code: [AUSKLAPPEN] Function LinesIntersect(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# intersection_x# = ax# + intersection_ab#*(bx#-ax#) intersection_y# = ay# + intersection_ab#*(by#-ay#) DrawOval intersection_x#-4,intersection_y#-4,9,9 If intersection_ab#>0 And intersection_ab#<1 And intersection_cd#>0 And intersection_cd#<1 Then Return True EndIf End Function Beispiel: Code: [AUSKLAPPEN] Graphics 800,600,0,60
SetColor 255,255,255 Repeat Cls SetColor 255,255,255 If LinesIntersect(600,400,400,300,MouseX()-100,MouseY()+100,MouseX()+100,MouseY()-100) Then DrawText "KOLLISION!",10,30 DrawLine 600,400,400,300 DrawLine MouseX()-100,MouseY()+100,MouseX()+100,MouseY()-100 Flip Until KeyHit(KEY_ESCAPE) |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group