We help IT Professionals succeed at work.

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.
Watch Question

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.


i wish i had listened during math lectures :-)


i will try to convert this to action script


was excellent if i had understood the math :-)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.