Found cordinates on circumference

07/05/2014 14:56 fuso98#1
Hi guys, i've a problem:
i want to find a specific point on a circumference (that there is not on the screen but i can only calculate every point).
My script need to find a picture on the screen, so it get direction line that pass by the center of my circumference and by the center of the picture, so now I have to find the intersection point originated from the line and the circle.
This image will help you:

[Only registered and activated users can see links. Click Here To Register...]

Until now i made this, but it not find the point well :(
PHP Code:
  $Midx=@DesktopWidth/2
  $Midy
=@DesktopHeight/2
  $x
=0
  $y
=0
$tag 
=_IMAGESEARCH(@ScriptDir "\Images\pt.bmp"1,$x,$y18)
If 
$tag=1 Then
  $dir
=point_direction($Midx,$Midy,$x,$y)
ClickCircleFromDir($dir,200)
EndIf

Func ClickCircleFromDir($dir,$radius)
  
$Midx=@DesktopWidth/2
  $Midy
=@DesktopHeight/2
 Mouseclick 
("left",$Midx + ($radius Cos($dir)),$Midy + ($radius Sin($dir)),1,0)
EndFunc

Func point_direction
($x1,$y1,$x2,$y2)
  
Local $dir1,$dir2,$dist
  $dist
=point_distance($x1,$y1,$x2,$y2);get the radius
  $dir1
=ACos(($x2-$x1)/$dist)*(360/3.14);X-derrived angle
  $dir2
=ASin(($y1-$y2)/$dist)*(360/3.14);Y-derrived angle
   
if ($dir2<0Then 
  
return $dir1-(2*$dir2);
   else 
  return 
$dir1
  
EndIf
 return -
1//Error!
EndFunc

Func point_distance
($x1$y1$x2$y2)
    
Local $a$b$c
    
If $x2 $x1 And $y2 $y1 Then
        
Return 0
    
Else
        
$a $y2 $y1
        $b 
$x2 $x1
        $c 
Sqrt($a $a $b $b)
        Return 
$c
    
EndIf
EndFunc   ;==>Pixel_Distance 
07/05/2014 15:14 butter123#2
seems like a basic math problem. though i dont really understand wich information are given. you want to get the x,y of the blue point?
and you have the x,y of the center, the radius and...?
07/05/2014 16:03 fuso98#3
the angle of the direction line
07/05/2014 17:04 butter123#4
so this is the interesting part:
PHP Code:
Func ClickCircleFromDir($dir,$radius)
  
$Midx=@DesktopWidth/2
  $Midy
=@DesktopHeight/2
 Mouseclick 
("left",$Midx + ($radius Cos($dir)),$Midy + ($radius Sin($dir)),1,0)
EndFunc 
math is correct, if angle is 0 at at x axis and is 90° if at top. chek this in ur point_direction func (i didnt check the math here). also check if it has to be ° or radian.

alternative way: create a function f=a+b*x from pic and center position and use the function value with binary search untill you have the point with needed radius.
07/06/2014 13:12 fuso98#5
I need to do it fast, so binary search will take much time maybe
07/06/2014 14:29 butter123#6
thats how i would have made the angle calculation:
angle =atan(y/x) ;y = ydistance between center and pic...
if x<0 and y >0 then angle = Pi - angle
if x<0 and y< 0 then angle = Pi + angle
if x>0 and y< 0 then angle = 2*Pi - angle
(didnt test it, jsut from mind. if... could be mixed) (result in radian)
07/10/2014 00:05 FacePalmMan#7
Use this:
Code:
Func CalcAngle($x1,$y1,$x2,$y2)
	Local $radAdd=0
	Local $X=($x2-$x1)
	Local $Y=($y2-$y1)
	Select
		Case $Y<0 and $X<0
			$radAdd=$pi
			Return ATan((-$Y)/(-$X)) + $radAdd
		Case $Y<0
			$radAdd=2*$pi
			Return $radAdd - ATan((-$Y)/$X)
		Case $X<0
			$radAdd=$pi
			Return $radAdd - ATan($Y/(-$X))
		Case Else
			Return ATan($Y/$X)
	EndSelect
EndFunc

Func MovXYbyAngle($x,$y,$angle,$Distance,$IsDeg=1)
	If $IsDeg=1 then $Angle/=180/3.14159
	Local $aReturn[2]=[$x+(Sin($Angle)),$y+(Cos($Angle))]
	Return $aReturn
Endfunc
and with the second function you can even make games.