I have 4 points, each of them indicates the middle of sides of rectangle.The 5th(main) point can be placed anywhere. How can I find the nearest of those 4 points to the main point, what is code implementation?
-
2Do you know how to calculate distance between two points?– Oliver CharlesworthNov 24, 2011 at 15:16
-
use pythagoras to find the distance between the clicked point and the fixed points– MoonlightNov 24, 2011 at 15:17
-
More suited for math.stackexchange.com ?– QwerkyNov 24, 2011 at 15:46
-
Just make an http request to wolframalpha.com/input/… and parse the results. Simple.– Matthew FarwellNov 24, 2011 at 15:54
Add a comment
|
1 Answer
Calculate the difference between the x- and y- coordinates of each point relative to yours. Then use pythagorus theorum to determine the actual distance from your point.
-
-
Sorry but I cant understand how should I use pythagorus theorum to determine the actual distance from my point, would you please write more detailed answer– MartinNov 24, 2011 at 16:21
-
If your point has coordinates (x,y) and another point is at (p,q) then the vertical distance between them is y-q (i.e y minus q) and the horizontal distance is x-p. These lengths are the shorter two sides of a right-angled triangle (draw it on a piece of paper - it's more obvious), so the hypoteneuse is the distance between the two points. In other words... sqrt( (x-p)^2 + (y-q)^2 ) Nov 24, 2011 at 20:26