Collisionline?
Übersicht

![]() |
FOODyBetreff: Collisionline? |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo.
Ich hab jetzt wiedermal ein Berechnungsproblem. Wie kann man herausfinden ob sich zwei linien schneiden? Hab die Suche benutzt aber leider nichts gefunden ![]() MfG, Mr. FOODS |
||
![]() |
BtbN |
![]() Antworten mit Zitat ![]() |
---|---|---|
In die Suche "Schnittpunkt" eingegeben und nach 2Min hatte ich:
http://blitzbase.de/quellcode/linienkreuzung.bb Sollte nicht all zu schwer nach BMax umzuschreiben sein. Ich mach mich ma ran. Edit: Ok, hier erstmal ne Funktion, die einfach nur True/Fals zurück gibt, ob sich die 2 Linien kreuzen: Code: [AUSKLAPPEN] Function LinesIntersect:Int(ax:Float, ay:Float, bx:Float, by:Float, cx:Float, cy:Float, dx:Float, dy:Float)
If ((bx-ax)*(dy-cy)-(by-ay)*(dx-cx)) = 0 Then Return False Else Return True EndIf End Function Bsp: Code: [AUSKLAPPEN] Function LinesIntersect:Int(ax:Float, ay:Float, bx:Float, by:Float, cx:Float, cy:Float, dx:Float, dy:Float)
If ((bx-ax)*(dy-cy)-(by-ay)*(dx-cx)) = 0 Then Return False Else Return True EndIf End Function Print LinesIntersect(5,5,5,200,.. 'Line 1 150,5,150,200) 'Line 2 Print LinesIntersect(5,5,150,200,.. 'Line 3 150,5,5,200) 'Line 4 Graphics(320,240,0,75) Cls SetColor(255,0,0) DrawLine(5,5,5,200) 'Line 1 DrawLine(150,5,150,200) 'Line 2 SetColor(0,255,0) DrawLine(5,5,150,200) 'Line 3 DrawLine(150,5,5,200) 'Line 4 Flip WaitKey() End Die Funktion mit den ganzen anderen Sachen kann ich bei Bedarf auch noch machen. |
||
- Zuletzt bearbeitet von BtbN am Mi, Jun 07, 2006 16:32, insgesamt 2-mal bearbeitet
![]() |
FOODy |
![]() Antworten mit Zitat ![]() |
---|---|---|
Cool danke.
Ich habe nur nach "collide line" und "collision line" gesucht >_> Umgeschrieben hab ich das so: (aufs schnelle 'türlich) Code: [AUSKLAPPEN] Global intersection_x#
Global intersection_y# Global intersection_ab# Global intersection_cd# Graphics 400,300,0 While Not KeyDown(KEY_ESCAPE) Cls x=MouseX() y=MouseY() intersection=lines_intersect(50,200,250,100, x-50,y-25,x+50,y+25) DrawText 0,0,intersection_ab# DrawText 0,20,intersection_cd# DrawLine 50,200,250,100 DrawLine x-50,y-25,x+50,y+25 If intersection=0 Or intersection_ab#<0 Or intersection_ab#>1 Or intersection_cd#<0 Or intersection_cd#>1 Then DrawText "Linien kreuzen nicht",0,40 Else DrawText "Linien kreuzen",0,40 SetColor 255,0,0 DrawOval intersection_x#-4,intersection_y#-4,9,9 EndIf SetColor 255,255,255 Flip Wend End 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# intersection_x# = ax# + intersection_ab#*(bx#-ax#) intersection_y# = ay# + intersection_ab#*(by#-ay#) Return True EndIf End Function Danke dir! EDIT: Etwas verbessert den Code. .:: FOODy |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group