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 › MouseClicked on Line (Vector)
Page Index Toggle Pages: 1
MouseClicked on Line (Vector)? (Read 499 times)
MouseClicked on Line (Vector)?
Nov 25th, 2007, 3:02pm
 
Hey,
On MouseClicked I want to know if I catches a line in an 3dimensional room. (to ease that up, we can take a 2dimensional room)
The line is drawn from a vector or a coordinate and the center of the room. Between this long line there is other point given.
Is there an (easy) way to calculate this?
I have about up to 100 lines so I don't want to overload my computer.

Re: MouseClicked on Line (Vector)?
Reply #1 - Nov 26th, 2007, 6:13pm
 
What I have to do to get an answer? If you dont understand my question, please ask.
Re: MouseClicked on Line (Vector)?
Reply #2 - Nov 26th, 2007, 8:42pm
 
Your question is a little vague, but one option is to do a dot-product of a normalisedvector from one point of the line and the mouse, and another normalised vector from the same point on the line to another point on the line.

If the mouse is on the line, the dot product should be 1 (or very close)
Re: MouseClicked on Line (Vector)?
Reply #3 - Nov 28th, 2007, 1:31pm
 
Great tipp, thanks. It worked out. Smiley

But one problem is there: I have choised a perspective (translate(width/2, height/2, -wSize/3)) and the mouse position only gets the coordinates of the 'sketch-window' (dont know the name of it).
How can I handle this?

Re: MouseClicked on Line (Vector)?
Reply #4 - Nov 28th, 2007, 2:33pm
 
Oh, I realized: there was no problem with the perspective Smiley

Thanks for your help.
Page Index Toggle Pages: 1