Feb 7th, 2009, 08:59 AM
#1
Thread Starter
New Member
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
Feb 7th, 2009, 09:25 AM
#2
Re: intersect in two rectangles for VB2008
First you mention rectangle, then polygon. Which is it? For rectangles, use the Rectangles IntersectsWith method.
Feb 7th, 2009, 04:42 PM
#3
Thread Starter
New Member
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
Last edited by troxaio; Feb 7th, 2009 at 05:30 PM .
Feb 7th, 2009, 05:40 PM
#4
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.
Feb 8th, 2009, 10:47 AM
#5
Thread Starter
New Member
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
Feb 8th, 2009, 05:15 PM
#6
Addicted Member
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:
Public Shared Function PolygonsInterset(ByVal poly1 As System.Drawing.Drawing2D.GraphicsPath, ByVal poly2 As System.Drawing.Drawing2D.GraphicsPath) As Boolean
poly1.Flatten()
poly2.Flatten()
For Each pt As System.Drawing.PointF In poly1.PathPoints
If poly2.IsVisible(pt) Then
Return True
End If
Next
Return False
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
Forum Rules
Click Here to Expand Forum to Full Width