[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Line intersects rectangle?

Hi,

How can I test if a line (defined by two x,y endpoints) intersects a rectangle?

I have a bunch of rectangles draw on a screen, and want to know if a user's mouse intersects any of them when they move the mouse. I only get mouse move messages every so often, so if the user moves the mouse fast enough, most of the mouse location points are missed. So I'm looking to figure out which rectangles could have been intersected between two mouse points.

Thanks
0
DJ_AM_Juicebox
Asked:
DJ_AM_Juicebox
  • 3
  • 3
2 Solutions
 
GwynforWebCommented:
0
 
ozoCommented:
http://www.siggraph.org/education/materials/HyperGraph/scanline/clipping/cliplb.htm
says that Liang-Barsky is a 36% speed improvement over  Cohen -Sutherland for 2D lines
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
GwynforWebCommented:
...the questioner is not clipping,  just detecting incidence with the rectangular.
0
 
ozoCommented:
that's what line clipping algorithms do
0
 
GwynforWebCommented:
...line clipping gives the clipped line segment. That is different than just detecting if the line crosses the rectangle.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now