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 & HelpPrograms › Hit Testing A Diagonal Line.
Page Index Toggle Pages: 1
Hit Testing A Diagonal Line. (Read 687 times)
Hit Testing A Diagonal Line.
Apr 8th, 2010, 4:59pm
 
Hi all.

How would I go about hit testing a diagonal line?

For example, I have a vertical line, and am checking for a particular range of X values, followed by a range of Y values, contained within four 'if' statements (see code below). This works fine.

if(x1 >= 100){
       if(x1 <= 200){
         if(y1 >= 100){
           if(y1 <= 200){
             p1 = true;
           }
         }
       }
     }

However, on a diagonal line, the X condition changes depending on the Y value. Is there a way to construct this structure above to change the X value depending on the Y value? Or perhaps a completely different method?

Many thanks.
Re: Hit Testing A Diagonal Line.
Reply #1 - Apr 8th, 2010, 5:08pm
 
i am not sure if i get you right but Casey has some nice intersection examples online http://www.openprocessing.org/portal/?userID=54
Re: Hit Testing A Diagonal Line.
Reply #2 - Apr 8th, 2010, 5:11pm
 
You're into line-(something) intersection. So you should define what your other shape is. Search for e.g. line-circle intersection. There are plenty of processing libs that do that I guess.
Re: Hit Testing A Diagonal Line.
Reply #3 - Apr 8th, 2010, 5:12pm
 
Brilliant, thanks a lot.

Yes, he seems to be demonstrating exactly what I was after.

Thanks again.
Re: Hit Testing A Diagonal Line.
Reply #4 - Apr 8th, 2010, 5:12pm
 
heh cedric u got me there Tongue
Re: Hit Testing A Diagonal Line.
Reply #5 - Apr 8th, 2010, 5:20pm
 
Smiley

if shapes are getting more complex, http://www.ricardmarxer.com/geomerative/ is another way to go.
Re: Hit Testing A Diagonal Line.
Reply #6 - Apr 8th, 2010, 5:25pm
 
That's excellent. Thanks for your quick help.
Page Index Toggle Pages: 1