Jump to content
  • Advertisement
Sign in to follow this  
Jacob Roman

[RESOLVED]Mouse within 2D circle

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
XC ;circle's X center
YC ;circle's Y center
RC ; circle radius
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 :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!