Brauche Hilfe , Bitte ! ,. Vektorrechnug , Schnittpunkt

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

 

c64

Betreff: Brauche Hilfe , Bitte ! ,. Vektorrechnug , Schnittpunkt

BeitragSo, März 12, 2006 14:17
Antworten mit Zitat
Benutzer-Profile anzeigen
So ich habe mich nun schon 3 Tage abgeackert und gelernt und es bringt nix, sicher bin ich jetzt ein wenig schlauer Smile . Aber das was ich erreichen wollte habe ich leider nicht geschafft , Vielleicht bekomme ich es garnicht hin weil mir das Mathematische verständniss dazu fehlt , oder vielleicht drehe ich mich einfach nur im Kreis und bin schon auf dem richtigem Wege ?! .

Naja wie auch immer ich habe nun also einen Code zusammengestellt um die Hilfe eurerseits zu vereinfachen Smile .

Ich würde Gerne prüfen Ob die beiden Polygone miteinander Collidieren.

Mouse Left DOWN = Bewegt kleines POLY
Mouse RIGHT DOWN = Bewegt grosses POLY
Mouse CNTR DOWN = ROTIERT Zuletzt bewegtes Poly

Space Ein und ausschalten des von mir bisher errechneten Zeugs
(wobei ich zweifel dass das alles stimmt , naja und wenn es das tun würde bräuchte ich ja keine Hilfe ).

Die ganze Collisionsüberprüfung findet in CHK_Collide statt .

benutzt werden folgene Punkte

für Vektor 1 V1x1 , V1y1 , V1x2 , V1y2
für Vektor 2 V2x1 , V2y1 , V2x2 , V2y2

Also ich habe eigentlich garkein wissen über dieses Thema und alles was ich bis jetzt weiss habe ich in den letzten 3 Tagen gelernt . Nur leider reicht das nicht . Sad Also ich wäre euch sehr dankbar wenn mir nun jemand ein Wenig Helfen könnte und mir mit meinem Code ein wenig weiter hilft . Smile Ich werde bestimmt nicht aufgeben Smile , aber Es würde mir sehr weiterhelfen von jemanden der auf diesem Gebiet Wissend ist Hilfe zu bekommen Wink !!! , Ich möchte nicht "nur" Fertigen Code haben (sicher erstmal schon Wink !! ) Ich möchte die Ganze Sache auch vernünftig verstehen .



Und ich denke es wäre bestimmt nicht nur mir geholfen Damit !!

Ein ganz Dickes Danke Schonmal !


Code: [AUSKLAPPEN]

'/////////////////////////////////////////////////////////////////////////////////////
'
' LINE COLLISIONS MODELL
' -------------------------------
'
' Referenz :
'
' http://www.harveycartel.org/metanet/tutorials/tutorialA.html#eberly
' -------------------------------------------------------------------
'http://www.walter-fendt.de/m14d/
'http://www.euclideanspace.com/physics/dynamics/collision/twod/index.htm
'http://www.mathematik.net/geometrie/ge-001.htm
'http://wiki.delphigl.com/index.php/Tutorial_Lineare_Algebra
'/////////////////////////////////////////////////////////////////////////////////////


 Strict

 Global show:Int


 SeedRnd(MilliSecs())

  Type TPoint

       Field  POS_X  :Float          ..
           ,  POS_Y  :Float          ..
           , CPOS_X  :Float          ..
           , CPOS_Y  :Float          ..
           , DGR     :Float          ..
           , RX      :Float          ..
           , RY      :Float          ..
           , Collide :Byte           ..
           , PARENT  :Tpolygon ..


   
   '////////////////////////////////////////////////////
   '
   '
   '
   '
   
   Function create:TPoint(_DGR:Float,_RX:Float,_RY:Float)
                  
            Local NOBJECT:TPoint
   
                   NOBJECT=New TPoint
      
                  NOBJECT.rx  = _rx
                  NOBJECT.ry  = _ry
      
                 NOBJECT.Dgr = _Dgr
                      
               Return NOBJECT                      
                  
   EndFunction
   
   '////////////////////////////////////////////////////
   '
   '
   ' Render
   '
   
   Method Render()
   
           
           SetColor 50,250,50
   
                    DrawOval pos_X-3,pos_Y-3,6,6

        
    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' Render
   '

    Method Update()


    pos_X=parent.pos_X+(Sin (parent.rotation+dgr)*rx)
    pos_Y=parent.pos_Y+(Cos (parent.Rotation+dgr)*ry)


    If Self <> parent.Points.first()

   ' If pos_X < 0 Parent.pos_X:+26
   ' If pos_Y < 0 Parent.pos_Y:+26

   ' If pos_X > 600 Parent.pos_X:-26
   ' If pos_Y > 600 Parent.pos_Y:-26
   
    EndIf
                                 

    Render()
    EndMethod

  EndType                     

  Type TVektor

      Field px1:Float ..
          , py1:Float ..
          , px2:Float ..
          , py2:Float ..      

 Function Create:TVektor(x1:Float,y1:Float,x2:Float,y2:Float)

                  
            Local NOBJECT:TVektor
   
                  NOBJECT=New TVektor
   
                  NOBJECT.pX1=X1
                  NOBJECT.py1=Y1
                  NOBJECT.pX2=X2
                  NOBJECT.py2=Y2
                        
                Return NOBJECT    
  EndFunction

  Method Draw()

         SetLineWidth 10
         SetColor 255,255,255
         DrawLine px1,py1,px2,py2

         SetLineWidth 8
         SetColor 50,100,50
         DrawLine px1,py1,px2,py2

  EndMethod


  EndType



  Type Tpolygon
 
       Field pos_X      :Float ..
           , pos_Y      :Float ..
           , pos_X_OLD  :Float ..
           , pos_Y_OLD  :Float ..
         , ROTATION   :Float ..
         , SPD        :Float ..
         , PointS     :TLIST ..
         , Vektors    :TLIST ..
         , RDirection :Float ..
   
        Global Point_OBJECTS:TLIST   
      
         'M> MOVE
         'M> CHECK_COLLIDES
   
         Global LIST:TLIST
   
   '////////////////////////////////////////////////////
   '
   '
   '
   '
   
   Function create:Tpolygon(pos_X:Float,pos_Y:Float)
   
            If list=Null list=CreateList()
                  
            Local NOBJECT:Tpolygon
   
                  NOBJECT=New Tpolygon
               
                 NOBJECT.PointS=CreateList()
      
                  NOBJECT.pos_X=pos_X
                  NOBJECT.pos_Y=pos_Y
   
                  While NOBJECT.RDirection=0 NOBJECT.RDirection=Rand(-2,2) Wend
                  
                  list.Addlast(NOBJECT)
   
               Return NOBJECT                      
                  
    EndFunction

    '////////////////////////////////////////////////////
   '
   '
   ' CHK_COLLIDE
   '
   
 
Method chk_Collide()
   
            Local sCP               : TPOINT          ..
             , CO                : TPOLYGON        ..
            , CV                : TVEKTOR         ..   
               , V1X1              : Float           ..
               , V1Y1              : Float           ..
               , V1X2              : Float           ..
               , V1Y2              : Float           ..
               , V2X1              : Float           ..
               , V2Y1              : Float           ..
               , V2X2              : Float           ..
               , V2Y2              : Float           ..

                 
        Local DX:Float
        Local DY:Float
                                          
          Local DP:Float

        Local NX:Float
        Local   NY:Float

                        
          Local prj_X1:Float
        Local prj_Y1:Float

          Local prj_X2:Float
        Local prj_Y2:Float

          Local prj_X3:Float
        Local prj_Y3:Float


 SetLineWidth 1

'-----------------------------------------------------------
   
        For CO = EachIn LIST
            
            If CO <> Self And  CO.Vektors


                        For cV = EachIn CO.Vektors                               

                       
                          V1x1=cv.px1
                            V1Y1=Cv.py1 
               
                         V1x2=cv.px2
                         V1y2=cv.py2

   
                         For scp = EachIn Points
                           

                            V2x2 = pos_X
                            V2y2 = pos_Y
                        
                            V2x1 = scp.pos_X
                            V2y1 = scp.pos_Y
   
      
                      SetLineWidth 3
                     SetColor 250,100,100



                  
'-----------------------------------------------------------
   
          DX=v1x2-v1x1
          DY=v1y2-v1y1
                                 
            DP=Sqr(DX*DX+DY*DY)
   
          NX=DX/DP
           NY=DY/DP   
         If NX=0 NX=1
         If NY=0 NY=1
            

            prj_X1=( DP / (V1x1*v1x2) + (V1y1*v1y2) )*DX
           prj_Y1=( DP / (V1x1*v1x2) + (V1y1*v1y2) )*DY
 
          '  prj_X1=( DP / (DX*DX) + (DY*DY) )  * NX
         '  prj_Y1=( DP / (DX*DX) + (DY*DY) )  * NY

'--------------------------------------------------------
                                       
          DX=v2x2-v2x1
          DY=v2y2-v2y1
                                          
            DP=Sqr(DX*DX+DY*DY)

          NX=DX/DP
           NY=DY/DP
       
         If NX=0 NX=1
         If NY=0 NY=1
      
            
            prj_X2=( DP/ (V2x1*v2x1) + (V2y1*v2y2) )*DX 
            prj_Y2=( DP/ (V2x1*v2x2) + (V2y1*v2y2) )*DY

          '  prj_X2=( DP / (DX*DX) + (DY*DY) )  * NX
         '  prj_Y2=( DP / (DX*DX) + (DY*DY) )  * NY
               
'-----------------------------------------------------------

               
                         SetLineWidth 3
                     SetColor 100,250,100
                           
                     DrawLine v1x1,v1y1,v1x2,v1y2
           
                     SetColor 250,100,100
                     DrawLine v2x1,v2y1,v2x2,v2y2
            
                     If SHOW=1

                         SetLineWidth 1
                     SetColor 250,250,250
                     DrawLine v2x1,v2y1,prj_X2,prj_Y2
                   DrawLine v1x1,v1y1,prj_X1,prj_Y1
           
                     DrawOval v1x1-3,v1y1-3,6,6
                   DrawOval prj_X1+prj_X2-3,prj_y1+prj_y2-3,3,3
                                                     
                     EndIf

       Next
       Next 
      EndIf
     Next



    EndMethod
   
   
   '////////////////////////////////////////////////////
   '
   '
   ' ADD_Point
   '
   
   Method add_Point(_DGR:Float,_RX:Float,_RY:Float)
          PointS.addlast(TPoint.create(_DGR,_RX,_RY))
    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' ADD_Vektor
   '

   Method add_Vektor(x1:Float,y1:Float,x2:Float,y2:Float)
          Vektors.addlast(TVektor.create(x1,y1,x2,y2))
    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' Update
   '
   
   Method UPDATE()

   ' render
    Update_vektors
    chk_COLLIDE

    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' Render
   '
   
   Method Update_Vektors()
   
         If Points
      
           Local VL_px_1:Float ..
               , VL_py_1:Float ..
               , VL_px_2:Float ..
               , VL_py_2:Float ..             
               , VC     :Byte  ..
               
   
                 SetColor 250,250,250
                 DrawOval pos_X-2,pos_Y-2,4,4

                 Vektors=CreateList()


          Local Point:TPoint
   
                For Point = EachIn Points
   
                    Point.parent=Self
                
        
                    Point.Update()
                  
                    Select VC
   
                  
                    Case 0
   
                       VL_PX_1=Point.pos_X
                       VL_PY_1=Point.pos_Y
                        
                       VC=1
   
                   If VL_PX_2 And VL_PX_1 Add_Vektor VL_PX_2,VL_PY_2,VL_PX_1,VL_PY_1
   
                    Case 1
   
                       VL_PX_2=Point.pos_X
                       VL_PY_2=Point.pos_Y
                        
                       VC=0
                  
                               Add_Vektor VL_PX_1,VL_PY_1,VL_PX_2,VL_PY_2

         
   
                     EndSelect
   
                Next         

                   
                          Local VK_F:TPoint
                                   VK_F=TPoint(PointS.first())

                          Local VK_L:TPoint
                                   VK_L=TPoint(PointS.LAST())

                          Add_Vektor VK_L.pos_X,VK_L.pos_Y,Vk_F.pos_X,VK_F.pos_Y
   
   
           EndIf



    EndMethod
   '////////////////////////////////////////////////////
   '
   '
   ' Control
   '

    Method Render()
 
      Local l:Int
           If Vektors

           Local Vektor:TVektor

                 For Vektor=EachIn Vektors
                       
                     Vektor.Draw()
L:+1
                 Next
           EndIf
Print l

    EndMethod

   '////////////////////////////////////////////////////
   '
   '
   ' Control
   '

   
   Function Control()
   
    If list

             Local POLY:Tpolygon
   
                For POLY= EachIn LIST
   
   
                      Poly.Update            ()
                 '  Poly.RENDER            ()
                 
                Next
           
     EndIf
        
    EndFunction

  EndType


'/////////////////////////////////////////////////////////////////////////////////////
 
 Global OBJECT_PointS=5

   Global p1:TPolygon
          p1=Tpolygon.create(300,300)

    For Local cc=0 To Object_Points-1
    p1.add_Point ( (360/(Object_Points))*cc,50,50)
    Next
            
   Global p2:Tpolygon
          p2=Tpolygon.create(300,300)


    For Local cc=0 To Object_Points-1
    p2.add_Point ( (360/(Object_Points))*cc,70,70)
    Next


'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////


Function CNTRL()

  MXS=MXO-MouseX()
      MXO=MouseX()
      
 ps=Null

 If MouseDown(1) ps=p1
 If MouseDown(2) ps=p2

   If PS
   ls=ps
   PS.pos_X=MouseX() pS.pos_y=MouseY()
   EndIf

   If ls And MouseDown(3) ls.rotation :+MXs


   If KeyHit(key_Space) show=1-show

EndFunction
      

'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////


Global ps:Tpolygon
Global ls:Tpolygon
      
Global MXS :Int ..
     , MXO :Int ..
                                 


            Graphics 600,600



            Repeat



            If KeyHit(key_escape) End

            Cls
                                                               

            Tpolygon.CONTROL
            CNTRL


            Flip



            Forever



 

c64

BeitragSo, März 12, 2006 14:45
Antworten mit Zitat
Benutzer-Profile anzeigen
Habe jetzt von CodeMaster eine Function gefunden die mir schon Ein wenig weiter hilft .


Code: [AUSKLAPPEN]




'/////////////////////////////////////////////////////////////////////////////////////
'
' LINE COLLISIONS MODELL
' -------------------------------
'
' Referenz :
'
' http://www.harveycartel.org/metanet/tutorials/tutorialA.html#eberly
' -------------------------------------------------------------------
'http://www.walter-fendt.de/m14d/
'http://www.euclideanspace.com/physics/dynamics/collision/twod/index.htm
'http://www.mathematik.net/geometrie/ge-001.htm
'http://wiki.delphigl.com/index.php/Tutorial_Lineare_Algebra
'/////////////////////////////////////////////////////////////////////////////////////


 Strict

 Global show:Int


 SeedRnd(MilliSecs())

  Type TPoint

       Field  POS_X  :Float          ..
           ,  POS_Y  :Float          ..
           , CPOS_X  :Float          ..
           , CPOS_Y  :Float          ..
           , DGR     :Float          ..
           , RX      :Float          ..
           , RY      :Float          ..
           , Collide :Byte           ..
           , PARENT  :Tpolygon ..


   
   '////////////////////////////////////////////////////
   '
   '
   '
   '
   
   Function create:TPoint(_DGR:Float,_RX:Float,_RY:Float)
                 
            Local NOBJECT:TPoint
   
                   NOBJECT=New TPoint
     
                  NOBJECT.rx  = _rx
                  NOBJECT.ry  = _ry
     
                 NOBJECT.Dgr = _Dgr
                     
               Return NOBJECT                     
                 
   EndFunction
   
   '////////////////////////////////////////////////////
   '
   '
   ' Render
   '
   
   Method Render()
   
           
           SetColor 50,250,50
   
                    DrawOval pos_X-3,pos_Y-3,6,6

       
    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' Render
   '

    Method Update()


    pos_X=parent.pos_X+(Sin (parent.rotation+dgr)*rx)
    pos_Y=parent.pos_Y+(Cos (parent.Rotation+dgr)*ry)


    If Self <> parent.Points.first()

   ' If pos_X < 0 Parent.pos_X:+26
   ' If pos_Y < 0 Parent.pos_Y:+26

   ' If pos_X > 600 Parent.pos_X:-26
   ' If pos_Y > 600 Parent.pos_Y:-26
   
    EndIf
                                 

    Render()
    EndMethod

  EndType                     

  Type TVektor

      Field px1:Float ..
          , py1:Float ..
          , px2:Float ..
          , py2:Float ..     

 Function Create:TVektor(x1:Float,y1:Float,x2:Float,y2:Float)

                 
            Local NOBJECT:TVektor
   
                  NOBJECT=New TVektor
   
                  NOBJECT.pX1=X1
                  NOBJECT.py1=Y1
                  NOBJECT.pX2=X2
                  NOBJECT.py2=Y2
                       
                Return NOBJECT   
  EndFunction

  Method Draw()

         SetLineWidth 10
         SetColor 255,255,255
         DrawLine px1,py1,px2,py2

         SetLineWidth 8
         SetColor 50,100,50
         DrawLine px1,py1,px2,py2

  EndMethod


  EndType



  Type Tpolygon
 
       Field pos_X      :Float ..
           , pos_Y      :Float ..
           , pos_X_OLD  :Float ..
           , pos_Y_OLD  :Float ..
         , ROTATION   :Float ..
         , SPD        :Float ..
         , PointS     :TLIST ..
         , Vektors    :TLIST ..
         , RDirection :Float ..
   
        Global Point_OBJECTS:TLIST   
     
         'M> MOVE
         'M> CHECK_COLLIDES
   
         Global LIST:TLIST
   
   '////////////////////////////////////////////////////
   '
   '
   '
   '
   
   Function create:Tpolygon(pos_X:Float,pos_Y:Float)
   
            If list=Null list=CreateList()
                 
            Local NOBJECT:Tpolygon
   
                  NOBJECT=New Tpolygon
               
                 NOBJECT.PointS=CreateList()
     
                  NOBJECT.pos_X=pos_X
                  NOBJECT.pos_Y=pos_Y
   
                  While NOBJECT.RDirection=0 NOBJECT.RDirection=Rand(-2,2) Wend
                 
                  list.Addlast(NOBJECT)
   
               Return NOBJECT                     
                 
    EndFunction

    '////////////////////////////////////////////////////
   '
   '
   ' CHK_COLLIDE
   '
   
 
Method chk_Collide()
   
            Local sCP               : TPOINT          ..
               ,  CO                : TPOLYGON        ..



 SetLineWidth 1

'-----------------------------------------------------------
   
        For CO = EachIn LIST
           
            If CO <> Self And  CO.Vektors
   
                           For scp = EachIn Points
                           
                            If    Pointin( scp,CO)

                                  SetColor 255,0,0
                                  DrawOval scp.pos_X-5,scp.pos_Y-5,10,10
                            EndIf


       Next
      EndIf
     Next



    EndMethod
   
   
   '////////////////////////////////////////////////////
   '
   '
   ' ADD_Point
   '
   
   Method add_Point(_DGR:Float,_RX:Float,_RY:Float)
          PointS.addlast(TPoint.create(_DGR,_RX,_RY))
    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' ADD_Vektor
   '

   Method add_Vektor(x1:Float,y1:Float,x2:Float,y2:Float)
          Vektors.addlast(TVektor.create(x1,y1,x2,y2))
    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' Update
   '
   
   Method UPDATE()

    render
    Update_vektors
    chk_COLLIDE

    EndMethod



   '////////////////////////////////////////////////////
   '
   '
   ' Render
   '
   
   Method Update_Vektors()
   
         If Points
     
           Local VL_px_1:Float ..
               , VL_py_1:Float ..
               , VL_px_2:Float ..
               , VL_py_2:Float ..             
               , VC     :Byte  ..
               
   
                 SetColor 250,250,250
                 DrawOval pos_X-2,pos_Y-2,4,4

                 Vektors=CreateList()


          Local Point:TPoint
   
                For Point = EachIn Points
   
                    Point.parent=Self
               
       
                    Point.Update()
                 
                    Select VC
   
                 
                    Case 0
   
                       VL_PX_1=Point.pos_X
                       VL_PY_1=Point.pos_Y
                       
                       VC=1
   
                   If VL_PX_2 And VL_PX_1 Add_Vektor VL_PX_2,VL_PY_2,VL_PX_1,VL_PY_1
   
                    Case 1
   
                       VL_PX_2=Point.pos_X
                       VL_PY_2=Point.pos_Y
                       
                       VC=0
                 
                               Add_Vektor VL_PX_1,VL_PY_1,VL_PX_2,VL_PY_2

         
   
                     EndSelect
   
                Next         

                   
                          Local VK_F:TPoint
                                   VK_F=TPoint(PointS.first())

                          Local VK_L:TPoint
                                   VK_L=TPoint(PointS.LAST())

                          Add_Vektor VK_L.pos_X,VK_L.pos_Y,Vk_F.pos_X,VK_F.pos_Y
   
   
           EndIf



    EndMethod
   '////////////////////////////////////////////////////
   '
   '
   ' Control
   '

    Method Render()
 
      Local l:Int
           If Vektors

           Local Vektor:TVektor

                 For Vektor=EachIn Vektors
                       
                     Vektor.Draw()
L:+1
                 Next
           EndIf
Print l

    EndMethod

   '////////////////////////////////////////////////////
   '
   '
   ' Control
   '

   
   Function Control()
   
    If list

             Local POLY:Tpolygon
   
                For POLY= EachIn LIST
   
   
                      Poly.Update            ()
                 '  Poly.RENDER            ()
                 
                Next
           
     EndIf
       
    EndFunction

  EndType


'/////////////////////////////////////////////////////////////////////////////////////
 
 Global OBJECT_PointS=5

   Global p1:TPolygon
          p1=Tpolygon.create(300,300)

    For Local cc=0 To Object_Points-1
    p1.add_Point ( (360/(Object_Points))*cc,50,50)
    Next
           
   Global p2:Tpolygon
          p2=Tpolygon.create(300,300)


    For Local cc=0 To Object_Points-1
    p2.add_Point ( (360/(Object_Points))*cc,70,70)
    Next


'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////


Function CNTRL()

  MXS=MXO-MouseX()
      MXO=MouseX()
     
 ps=Null

 If MouseDown(1) ps=p1
 If MouseDown(2) ps=p2

   If PS
   ls=ps
   PS.pos_X=MouseX() pS.pos_y=MouseY()
   EndIf

   If ls And MouseDown(3) ls.rotation :+MXs


   If KeyHit(key_Space) show=1-show
EndFunction
     

'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////


Global ps:Tpolygon
Global ls:Tpolygon
     
Global MXS :Int ..
     , MXO :Int ..
                                 


            Graphics 600,600



            Repeat



            If KeyHit(key_escape) End

            Cls
                                                               

            Tpolygon.CONTROL
            CNTRL


            Flip



            Forever


                        
Function PointIN(Point:TPOINT,POLY:TPOLYGON)

         Local Vektor  :TVEKTOR           ..
             , px      :Int=POINT.pos_X   ..
             , py      :Int=POINT.pos_Y   ..
          , s       :Int               ..      
           
               For Vektor=EachIn POLY.Vektors

             
                  Local x1:Float=Vektor.px1
                  Local y1:Float=Vektor.py1
                  Local x2:Float=Vektor.px2
                  Local y2:Float=Vektor.py2
                  Local x3:Float
                  Local y3:Float
                                                                 
         If x2<x1   x3 = x2    x2=x1  x1=x3  y3=y2  y2=y1  y1=y3

               If (px >=x1) And (pX <=x2)
                 Local yp = y1 +(px -x1) * (y2 -y1 ) / ( x2 - x1 )
                 
                   If yp <= py Then s=s+1
                   
                   EndIf
               Next
     
Return S Mod 2

EndFunction

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group