Solved

Line intersects rectangle?

Posted on 2009-04-03
6
266 Views
Last Modified: 2012-05-06
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
Comment
Question by:DJ_AM_Juicebox
  • 3
  • 3
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 24065536
0
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 250 total points
ID: 24065595
0
 
LVL 84

Expert Comment

by:ozo
ID: 24065652
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 31

Expert Comment

by:GwynforWeb
ID: 24065826
...the questioner is not clipping,  just detecting incidence with the rectangular.
0
 
LVL 84

Expert Comment

by:ozo
ID: 24066020
that's what line clipping algorithms do
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 24066221
...line clipping gives the clipped line segment. That is different than just detecting if the line crosses the rectangle.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Probability 2 47
Permutation and Combination 9 48
Calculating Standard Deviation inside Excel. 5 54
Currency Conversion? 1 39
A Guide to the PMT, FV, IPMT and PPMT Functions In MS Excel we have the PMT, FV, IPMT and PPMT functions, which do a fantastic job for interest rate calculations.  But what if you don't have Excel ? This article is for programmers looking to re…
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now