Calculating Proximity

I have a canvas which has lines draw by the user at random, what i need to do is calculate which line has the closest end or start point to the mouse it is clicked.
Can anyone help here please.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you know the x,y coordinates you can simply use pythagorus:
3 coordinates mouse (Xm, Ym, start of line (x1, y1) and end iof line (x2, y2)

To work out the smalest of these 2 numbers:

Start of line:
(Xm - x1)^2 + (Ym- y1)^2

End of line:
(Xm - x2)^2 + (Ym- y2)^2

The smallest number will be the shortest distance from the mouse.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robinsonx6Author Commented:
i wish i had listened during math lectures :-)


i will try to convert this to action script
Robinsonx6Author Commented:
was excellent if i had understood the math :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.