polaris2490 Posted May 2, 2007 Share Posted May 2, 2007 My problem is "How to detect the nearest target" EX : I got a green point at (x,y) pixel and many white points around me . So , how to detect which is the nearest ? thank you very much Link to comment Share on other sites More sharing options...
SadBunny Posted May 2, 2007 Share Posted May 2, 2007 My problem is "How to detect the nearest target"EX : I got a green point at (x,y) pixel and many white points around me . So , how to detect which is the nearest ?thank you very muchPythagoras?For each point, calculate Sqrt((Xwhite-Xgreen)^2+(Ywhite-Ygreen)^2). Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
polaris2490 Posted May 2, 2007 Author Share Posted May 2, 2007 too much points - can't not calculate thank for help . i'm waiting for another solution Link to comment Share on other sites More sharing options...
ofLight Posted September 5, 2007 Share Posted September 5, 2007 (edited) I realize this is an old thread, but I just wanted to say Thanks SadBunny. Your Suggestion works incredibly well, I never woulda figured that one out on my own ;================================= Closest ============================= ; Function Name: _Closest ; Description: Calculate which CoOrds are Closer ; Parameters: $Array Array of CoOrds to check against the Center Location ; $XCenter Center X CoOrd ; $YCenter Center Y CoOrd ; Syntax: _Closest($Array,$XCenter,$YCenter) ; Author(s): ofLight ; Returns: $output[0] = 0 on failure, $output[0] > 0 on Success ;============================================================================ Func _Closest($Array,$XCenter,$YCenter) Dim $output[$Array[0][0]+1] $output[0] = $Array[0][0] For $i = 1 to $Array[0][0] $output[$i] = Round(Sqrt(($Array[$i][0]-$XCenter)^2+($Array[$i][1]-$YCenter)^2),2) Next $t = 0 $s = $output[1] For $i = 1 to $output[0] If $output[$i] < $s Then $s = $output[$i] $t = $i EndIf Next Dim $output[2] $output[0] = $Array[$t][0] $output[1] = $Array[$t][1] Return $output EndFunc EDIT: posted wrong Code , thanks for the heads up Edited September 6, 2007 by ofLight There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now