twixman Posted December 26, 2006 Posted December 26, 2006 (edited) Hello ! I made a function that draw a circle with the mouse. In this function, I have an argument that is the angle where the circle is starting drawn. With another function, I click on the screen a first time to point where the circle will start to be drawn, and a second time to point the center of my circle. My problem is I don't manage to calculate the angle with this two points. Here is my code : expandcollapse popupFunc ask_circle() $angle = InputBox("Angle", "Please type in the angle in degrees you want it draws (360 is a full rotation).Click on OK and then, click one time on your screen for where the circle will start to be drawn, and a second time for the center.", 90) If @error = 1 Then MsgBox(64, "Cancelled", "Action cancelled") Exit EndIf Sleep(300) While 1 If _IsPressed("01") Then $start_pos = MouseGetPos() ExitLoop EndIf WEnd Sleep(300) While 1 If _IsPressed("01") Then $ctr_pos = MouseGetPos() ExitLoop EndIf WEnd $diam = Sqrt( ( $ctr_pos[1] - $start_pos[1] ) * ( $ctr_pos[1] - $start_pos[1] ) + ( $ctr_pos[0] - $start_pos[0] ) * ( $ctr_pos[0] - $start_pos[0] ) ) $sinus = ( $start_pos[1] - $ctr_pos[1] ) / $diam $cosinus = ( $start_pos[0] - $ctr_pos[0] ) / $diam $angle_init = _Degree(ACos($cosinus)) ;~ If $cosinus >= 0 Then ;~ If $sinus >= 0 Then ;~ $angle_init = $angle_init ;~ Else ;~ $angle_init = 270 + $angle_init ;~ EndIf ;~ Else ;~ If $sinus >= 0 Then ;~ $angle_init = 270 - $angle_init ;~ Else ;~ $angle_init = 180 - $angle_init ;~ EndIf ;~ EndIf Sleep(300) Circle($ctr_pos[0], $ctr_pos[1], $diam, $angle_init, $angle) EndFunc $angle_init should be the angle between the horizontal line of the center and the line formed with the two points (center, and starting point) $ctr_pos is [x,y] coords of the center $start_pos is [x,y] coords of the starting point $diam is the diameter This code : ;~ If $cosinus >= 0 Then ;~ If $sinus >= 0 Then ;~ $angle_init = $angle_init ;~ Else ;~ $angle_init = 270 + $angle_init ;~ EndIf ;~ Else ;~ If $sinus >= 0 Then ;~ $angle_init = 270 - $angle_init ;~ Else ;~ $angle_init = 180 - $angle_init ;~ EndIf ;~ EndIf is the way I wanted to do calculate the angle, but it does not work. Need your help ! Thank you, cya Edited December 26, 2006 by twixman intrepid
twixman Posted December 26, 2006 Author Posted December 26, 2006 I made many test that I found logical and I had always problem in my tests.... So I checked everything and I found the problem came from the function _Degree() that sometime returned nothing My new code is : $diam = Sqrt( ( $ctr_pos[1] - $start_pos[1] ) * ( $ctr_pos[1] - $start_pos[1] ) + ( $ctr_pos[0] - $start_pos[0] ) * ( $ctr_pos[0] - $start_pos[0] ) ) $radtodeg = 57.2957795130823 $angle_init = ACos(($start_pos[0] - $ctr_pos[0]) / $diam) * $radtodeg If $start_pos[1] > $ctr_pos[1] Then $angle_init = - $angle_init intrepid
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