Results 1 to 6 of 6

Thread: Polygon Vertices Intersection?

  1. #1

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Polygon Vertices Intersection?

    Does anybody have an efficient way of detecting if a polygons vertices intersect (non-simple polygon) given a series of points?

    Thanks,

    Christian
    In life you can be sure of only two things... death and taxes. I'll take death.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Polygon Vertices Intersection?

    2D or 3D?

  3. #3

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: Polygon Vertices Intersection?

    2D, sorry.
    In life you can be sure of only two things... death and taxes. I'll take death.

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Polygon Vertices Intersection?

    If this is a pure math question, here is a paper for you.

    http://wscg.zcu.cz/wscg2004/Papers_2004_Full/B83.pdf



    If you are trying to do this for a game or something, and you are using BitBlt, or DDraw or something there is much nicer ways to do it.




    ØØ

  5. #5

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: Polygon Vertices Intersection?

    I am not a huge math or geometry buff and just need a simple code example be it VB C# C++ or whatever that will allow me to calculate when two lines of a polygon intersect.

    I can break it up into lines and interogate the x,y coordinates I suppose:

    Code:
        Private Structure line
            Dim StartPoint As PointF
            Dim EndPoint As PointF
        End Structure
    
    
                Dim Lines() As line
                For i As Integer = 0 To num
                    If i < num Then
                        ReDim Preserve Lines(i)
                        Lines(i) = New line
                        Lines(i).StartPoint = New PointF(Pts(i).X, Pts(i).Y)
                        Lines(i).EndPoint = New PointF(Pts(i + 1).X, Pts(i + 1).Y)
                    Else
                        ReDim Preserve Lines(i)
                        Lines(i) = New line
                        Lines(i).StartPoint = New PointF(Pts(i).X, Pts(i).Y)
                        Lines(i).EndPoint = New PointF(Pts(0).X, Pts(0).Y)
                    End If
                Next
    
                Dim LinesIntersect As Boolean = False
                For Each FirstLine As line In Lines
                    For Each SecondLine As line In Lines
                        'do comparisions from first line to second line
                    Next
                Next
    I just thought there might be a more elegant algorithm.

    Thanks.
    In life you can be sure of only two things... death and taxes. I'll take death.

  6. #6

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: Polygon Vertices Intersection {RESOLVED}?

    This post finished my code:

    http://www.vbforums.com/showthread.p...29#post1951829

    incombination with this.
    Code:
                Dim li As Boolean = False
                For Each FirstLine As line In Lines
                    For Each SecondLine As line In Lines
                        If MS_INTERSECT(FirstLine.StartPoint, FirstLine.EndPoint, SecondLine.StartPoint, SecondLine.EndPoint) Then
                            li = True
                        End If
                    Next
                Next
                If li Then
                    Return 0
                End If
    Thanks.
    In life you can be sure of only two things... death and taxes. I'll take death.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width