Solved

Line intersects rectangle?

Posted on 2009-04-03
6
270 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Frequency distribution 6 49
Formula to Randomize Data Set for Time Series Visual 1 108
Standard Deviation 2 36
hardness of water, iron in it, and effect on humans.. 6 81
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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