
Challenging Convention
Find Mouse Position Within Circle
Hi Guys,
K, this is really doing me in, and i know it'll be easy for you geniuses
I have a circle, of which the outer ring is a button, i need to know (as a percentage) where the mouse was clicked within that active area.
Here is an illustration:
The whole circle will be inside a clip and the actual circle may vary in size so ideally i need it to know it's own _width and tell me where the mouse clicked as a percentage between points A & B. Also, it must be able to work when clicking at any point in the circle (top, bottom, left, right etc.)
LOL, after 3 or 4 hours of trial & error trying it with pure Math, i was tempted to just say "F*** It" and make 100 individual progressively larger rings, make them buttons and name them 099
It seems like a really easy thing to do, but i am really struggling with it.
I would really appreciate any help.
Thanks in advance,
Andy
Last edited by Andology; 07302008 at 07:15 PM.

The winded solution is about trying to find out the radius that crosses that point and then take the distance from the point to the limit of the circle.
But well, the length of the radius remains the same all over the circle, so all you need to do is compute the distance between your point and the center of the circle and compare it to the length of the radius ;). (or in your case, the distance that corresponds to the radius of the outer circle  the radius of the inner one)
You will find plenty of information on how to compute the distance between two points on the web.
http://www.flzone.com/ShowDetail.asp?NewsId=3220
http://flaim.wordpress.com/2008/04/0...entwopoints/
http://blog.circlecube.com/2008/02/1...oreantheorem/
Last edited by widged; 07302008 at 08:38 PM.

Challenging Convention
Thanks for your response widged.. It helped in a way as the lack of clarity / specifics simply encouraged me to take another look at it to suss it out.
FYI, this is how i did it:
Code:
MousePos = Math.round(Math.sqrt(_xmouse*_xmouse+_ymouse*_ymouse));
InnerRad = InnerCircle._width/2;
OuterRad = OuterCircle._width/2;
WhatIWannaKnow = Math.floor(((MousePosInnerRad)/(OuterRadInnerRad))*100);
(i have broken up the equasion for the purposes of clarity to help others trying to read / understand the code)
Thanks again dude...
Cheers
Andy

No worries, mate. Glad you got it sorted and thanks for sharing :).

The formula for a circle:
(xh)^2+(yk)^2=r^2
(h,k) is the center
r is the radius
You want the equation for both circles, and you want to subtract the x and y values of each
The formula for your circles:
[[(x2h)^2][(xh)^2]] + [[(y2k)^2][(yk)^2]] = [r2^2r^2]
(h,k) is the center
r is the radius of small circle
r2 is the radius of large circle
y2 is of large circle
y is of small circle
x2 is of large circle
x is of small circle
This should be the equation for any point between the large and small circle. The brackets will be parenthesis of course. You will have to use Math.pow() also.
h and k are the same for both circles (it is the center for both)
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
