# [RESOLVED]Mouse within 2D circle

This topic is 4788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

It's been awhile since I did this, and I know it's easy, but I forgot how to do it. How can I determine that the mouse cursor is witin a 2D circle? [Edited by - Jacob Roman on November 3, 2005 10:13:00 PM]

##### Share on other sites
Details here. (The solution is the same for circles and spheres.) Short answer:
float x = mouse.x-circle.center.x;float y = mouse.y-circle.center.y;return (x*x+y*y) <= circle.radius*circle.radius;

##### Share on other sites
XC ;circle's X center
YC ;circle's Y center
XM ;mouse X coord
YM ;mouse Y coord

POINT_DIST = SQRT ((XC - XM) ^ 2 + (YC - YM) ^ 2)
IF POINT_DIST > RC THEN POINT_NOT_IN_CIRCLE = TRUE

Oops, too late :(

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013441
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!