We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › click-select a line
Page Index Toggle Pages: 1
click-select a line? (Read 733 times)
click-select a line?
May 18th, 2007, 6:07pm
 
I'm working on a GUI design, and I'm wondering how one might go about allowing a user to select a line by clicking on it? I've thought maybe of calculating little "bounding boxes" between each point, but that seems really tedious and calculation-heavy. The big hitch is that the line will be on top of another object, so the ability to accurately determine when a mouse-click is actually *on* the line is pretty important.

Any thoughts? This is done pretty reguarly in drawing programs, and the like, so I'm sure it's not a huge deal... but it would be nice to avoid re-inventing the wheel!

J.
Re: click-select a line?
Reply #1 - May 18th, 2007, 8:52pm
 
You'll almost certainly need to calc a distance for all lines, then compare and find the smallest, and verify that it falls within some selection tolerance distance.  Why?  Especially for non-orthogonal lines, the mouse will hardly ever truly be "on" the line in a mathematical sense, even when over one of the lit pixels from the rasterization.

How do you store your lines?  As two-point segments?  If so, then this is what you need:
http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
(if stored in some other form, either substitute in if you have the math, or google until you find it in the proper form)
Re: click-select a line?
Reply #2 - May 18th, 2007, 9:23pm
 
davbol wrote on May 18th, 2007, 8:52pm:
You'll almost certainly need to calc a distance for all lines, then compare and find the smallest, and verify that it falls within some selection tolerance distance.  Why  Especially for non-orthogonal lines, the mouse will hardly ever truly be "on" the line in a mathematical sense, even when over one of the lit pixels from the rasterization.

How do you store your lines  As two-point segments  If so, then this is what you need:
http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
(if stored in some other form, either substitute in if you have the math, or google until you find it in the proper form)


Great. Thanks for this. These will actually generally be hand-drawn lines, so they should have a lot of point data. I had thought it might be possible, in this case, to interpolate a point between the two closest points. Anyway, I'll take a more detailed look at your link.

cheers,

J.
Page Index Toggle Pages: 1