• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

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.
  • 2
1 Solution
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.

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 :-)

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now