|
|
Search Tutorials
How To Find The Mouse Location Why do we need to know the mouse location? Since the 0,0 coordinate in this demonstration never moves, all we need to know to do some Trigonometry is the length of two sides of the triangle. Since we do know two sides (the x and y value of the mouse are distances... and are the two sides of the triangle) we can calculate the third side of the triangle (the hypotenuse) using the formula (a^2 + b^2 = c^2). More on that:
Comment: ----------------------------------------------
Comment: determine hypotenuese length
Comment: ----------------------------------------------
Comment: a squared plus b squared = c squared... (c=hypotenuse) so what is c?
Set Variable: "input" = (mouse_x * mouse_x) + (mouse_y * mouse_y)
Call ("sqrt")
Set Variable: "hyp" = output
For now, let's just say you set a variable "input" call "sqrt" and it sends back a variable "output", which is the square root of the number you sent. Now we know the length of the hypotenuse. 'Hyp'. Since the x position of the user's mouse is "A" and the y position of the user's mouse is "O" we now have more than enough information to determine the angle "Theta". Comment: ---------------------------------------------- Comment: determine sin(theta) Comment: ---------------------------------------------- Comment: now we know "c" (the hypotenuse) how do we find the angle? Sine(Theta) is Opposite over Hypotenuse, then lookup the Sine value in the lookup table. Set Variable: "sin_theta" = mouse_y/hyp If (sin_theta<0) Set Variable: "sin_theta" = sin_theta+(sin_theta*-2) End If
|
||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||
|