Results 1 to 6 of 6

Thread: intersect in two rectangles for VB2008

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    7

    intersect in two rectangles for VB2008

    Hello all,

    how to know if two rectangles intersect

    i know for polygon center, length, width and angle

    i want to fast algorithm for visual basic 2008

    very thanks

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: intersect in two rectangles for VB2008

    First you mention rectangle, then polygon. Which is it? For rectangles, use the Rectangles IntersectsWith method.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    7

    Re: intersect in two rectangles for VB2008

    My rectangle is rotating.
    I have two rotating rectangle and i know width, height, center and angle for each rectangle.

    how to know if two rectangles intersect?

    The IntersectsWith Method works with rotating rectangle?
    Attached Images Attached Images  
    Last edited by troxaio; Feb 7th, 2009 at 05:30 PM.

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: intersect in two rectangles for VB2008

    IntersectsWith wont work with that no, simply because the Rectangle structure that exposes that method can not represent a rotated rectangle.

    You'll have to implement one of the many polygon clipping algorithms available...here are a few links that might get you going:
    http://www.codeguru.com/cpp/misc/mis...icle.php/c8965
    http://clippoly.sourceforge.net/appe...ppendices.html

    I also found this library that might be worth looking at.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    7

    Re: intersect in two rectangles for VB2008

    ok Atheist nice link.
    The function is ok, but I have a small problem.
    My rectangle i know width, height, center and angle for each rectangle.

    how to find the angle of the rectangle?
    Attached Images Attached Images  

  6. #6
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: intersect in two rectangles for VB2008

    This should work, if you put your polygons into two GraphicsPath objects:


    (just make sure they both have the same origin)


    vb Code:
    1. Public Shared Function PolygonsInterset(ByVal poly1 As System.Drawing.Drawing2D.GraphicsPath, ByVal poly2 As System.Drawing.Drawing2D.GraphicsPath) As Boolean
    2.         poly1.Flatten()
    3.         poly2.Flatten()
    4.         For Each pt As System.Drawing.PointF In poly1.PathPoints
    5.             If poly2.IsVisible(pt) Then
    6.                 Return True
    7.             End If
    8.         Next
    9.         Return False
    10.     End Function

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